feat: add support for MCP Sampling as AI provider#863
Conversation
…ster into orenm/mcpsampling
🦋 Changeset detectedLatest commit: a8609e8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Crunchyman-ralph
left a comment
There was a problem hiding this comment.
Great PR, will review again more thoroughly.
Mind if I ask which MCP clients this sampling will work for ?
There was a problem hiding this comment.
similar to how we made a custom sdk package for claude code, think we should have something similar for the sampling.
|
Thanks, tried to keep up to the standards I wrote it in the PR description but more in depth support for model selection can be extended Maybe I forgot it so will write here a sampling has timeout and tasks like analyze might take a while |
|
@OrenMe feel free to refactor what you're talking about in a separate, lets keep this PR scoped to adding the "sampling" as a provider As I mentioned, it would be nice to make the "sampling provider" a custom ai-sdk provider, that would work better with what we currently have (check out the claude code example) I'll be monitoring this more closely, let me know if there is anything else I can do to help! |
- Add MCP Sampling provider with custom-sdk pattern implementation - Support MCP preference-based model selection (hints and priorities) - Add comprehensive test coverage (69 tests) - Add usage documentation and implementation notes - Refactor from PR eyaltoledano#863 monolithic approach to modular design - Follow established claude-code provider patterns
|
Hi @OrenMe, sure I'll do it as soon as I can, thank you! |
|
strange I can't repro the error locally, this was the last error but after I pushed the gemini fix I can't repro locally, unless I revert it |
Hi @OrenMe, I started fresh by forking your repo and I don't have those errors anymore, so no need for an additional PR. Can't wait to see this in the next release, thank you :) |
|
Thanks @Ton-Git for verifying |
) (eyaltoledano#920) Gracefully handle SyntaxError thrown by @anthropic-ai/claude-code when the CLI truncates large JSON outputs (4–16 kB cut-offs).\n\nKey points:\n• Detect JSON parse error + existing buffered text in both doGenerate() and doStream() code paths.\n• Convert the failure into a recoverable 'truncated' finish state and push a provider-warning.\n• Allows Task Master to continue parsing long PRDs / expand-task operations instead of crashing.\n\nA patch changeset (.changeset/claude-code-json-truncation.md) is included for the next release.\n\nRef: eyaltoledano#913
Remove erroneous 'gemini auth login' command references and replace with correct 'gemini' command authentication flow. Update documentation to reflect proper OAuth setup process via the gemini CLI interactive interface.
…cation (eyaltoledano#932) - Fixed authentication compatibility issues with Google auth - Added support for 'api-key' auth type alongside 'gemini-api-key' - Resolved "Unsupported authType: undefined" runtime errors - Updated @google/gemini-cli-core dependency to 0.1.9 - Improved documentation and removed invalid auth references - Maintained backward compatibility while enhancing type validation
|
Seems to be working pretty well on cursor and CLI, falls back to the right fallback model. |
|
Testing on vscode, watch out for how you use this.logger inside MCP, this can crash the mcp server in stdio: |
Need to patch upstream fastmcp to allow easier access and bootstrap the TM mcp logger to use the fastmcp logger which today is only exposed in the tools handler
Crunchyman-ralph
left a comment
There was a problem hiding this comment.
lgtm, though feels like you have changes from other PRs, maybe we should merge origin/next ?
* feat: support MCP sampling * support provider registry * use standard config options for MCP provider * update fastmcp to support passing params to requestSampling * move key name definition to base provider * moved check for required api key to provider class * remove unused code * more cleanup * more cleanup * refactor provider * remove not needed files * more cleanup * more cleanup * more cleanup * update docs * fix tests * add tests * format fix * clean files * merge fixes * format fix * feat: add support for MCP Sampling as AI provider * initial mcp ai sdk * fix references to old provider * update models * lint * fix gemini-cli conflicts * ran format * Update src/provider-registry/index.js Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> * fix circular dependency Circular Dependency Issue ✅ FIXED Root Cause: BaseAIProvider was importing from index.js, which includes commands.js and other modules that eventually import back to AI providers Solution: Changed imports to use direct paths to avoid circular dependencies: Updated base-provider.js to import log directly from utils.js Updated gemini-cli.js to import log directly from utils.js Result: Fixed 11 failing tests in mcp-provider.test.js * fix gemini test * fix(claude-code): recover from CLI JSON truncation bug (eyaltoledano#913) (eyaltoledano#920) Gracefully handle SyntaxError thrown by @anthropic-ai/claude-code when the CLI truncates large JSON outputs (4–16 kB cut-offs).\n\nKey points:\n• Detect JSON parse error + existing buffered text in both doGenerate() and doStream() code paths.\n• Convert the failure into a recoverable 'truncated' finish state and push a provider-warning.\n• Allows Task Master to continue parsing long PRDs / expand-task operations instead of crashing.\n\nA patch changeset (.changeset/claude-code-json-truncation.md) is included for the next release.\n\nRef: eyaltoledano#913 * docs: fix gemini-cli authentication documentation (eyaltoledano#923) Remove erroneous 'gemini auth login' command references and replace with correct 'gemini' command authentication flow. Update documentation to reflect proper OAuth setup process via the gemini CLI interactive interface. * fix tests * fix: update ai-sdk-provider-gemini-cli to 0.0.4 for improved authentication (eyaltoledano#932) - Fixed authentication compatibility issues with Google auth - Added support for 'api-key' auth type alongside 'gemini-api-key' - Resolved "Unsupported authType: undefined" runtime errors - Updated @google/gemini-cli-core dependency to 0.1.9 - Improved documentation and removed invalid auth references - Maintained backward compatibility while enhancing type validation * call logging directly Need to patch upstream fastmcp to allow easier access and bootstrap the TM mcp logger to use the fastmcp logger which today is only exposed in the tools handler * fix tests * removing logs until we figure out how to pass mcp logger * format * fix tests * format * clean up * cleanup * readme fix --------- Co-authored-by: Oren Melamed <oren.m@gloat.com> Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Co-authored-by: Ben Vargas <ben@vargas.com>
* feat: support MCP sampling * support provider registry * use standard config options for MCP provider * update fastmcp to support passing params to requestSampling * move key name definition to base provider * moved check for required api key to provider class * remove unused code * more cleanup * more cleanup * refactor provider * remove not needed files * more cleanup * more cleanup * more cleanup * update docs * fix tests * add tests * format fix * clean files * merge fixes * format fix * feat: add support for MCP Sampling as AI provider * initial mcp ai sdk * fix references to old provider * update models * lint * fix gemini-cli conflicts * ran format * Update src/provider-registry/index.js Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> * fix circular dependency Circular Dependency Issue ✅ FIXED Root Cause: BaseAIProvider was importing from index.js, which includes commands.js and other modules that eventually import back to AI providers Solution: Changed imports to use direct paths to avoid circular dependencies: Updated base-provider.js to import log directly from utils.js Updated gemini-cli.js to import log directly from utils.js Result: Fixed 11 failing tests in mcp-provider.test.js * fix gemini test * fix(claude-code): recover from CLI JSON truncation bug (eyaltoledano#913) (eyaltoledano#920) Gracefully handle SyntaxError thrown by @anthropic-ai/claude-code when the CLI truncates large JSON outputs (4–16 kB cut-offs).\n\nKey points:\n• Detect JSON parse error + existing buffered text in both doGenerate() and doStream() code paths.\n• Convert the failure into a recoverable 'truncated' finish state and push a provider-warning.\n• Allows Task Master to continue parsing long PRDs / expand-task operations instead of crashing.\n\nA patch changeset (.changeset/claude-code-json-truncation.md) is included for the next release.\n\nRef: eyaltoledano#913 * docs: fix gemini-cli authentication documentation (eyaltoledano#923) Remove erroneous 'gemini auth login' command references and replace with correct 'gemini' command authentication flow. Update documentation to reflect proper OAuth setup process via the gemini CLI interactive interface. * fix tests * fix: update ai-sdk-provider-gemini-cli to 0.0.4 for improved authentication (eyaltoledano#932) - Fixed authentication compatibility issues with Google auth - Added support for 'api-key' auth type alongside 'gemini-api-key' - Resolved "Unsupported authType: undefined" runtime errors - Updated @google/gemini-cli-core dependency to 0.1.9 - Improved documentation and removed invalid auth references - Maintained backward compatibility while enhancing type validation * call logging directly Need to patch upstream fastmcp to allow easier access and bootstrap the TM mcp logger to use the fastmcp logger which today is only exposed in the tools handler * fix tests * removing logs until we figure out how to pass mcp logger * format * fix tests * format * clean up * cleanup * readme fix --------- Co-authored-by: Oren Melamed <oren.m@gloat.com> Co-authored-by: Ralph Khreish <35776126+Crunchyman-ralph@users.noreply.github.com> Co-authored-by: Ben Vargas <ben@vargas.com>
Description
This PR introduces MCP Sampling as a new AI provider for Task Master, enabling the system to use MCP (Model Context Protocol) client capabilities as an AI provider without requiring API keys. The implementation includes a dynamic provider registry system that allows runtime registration of remote providers while maintaining backward compatibility with existing static providers.
Type of Change
Testing
Changeset
Additional Notes
Key Features
🔧 Provider Registry System
index.jsfor dynamic provider registration🌐 MCP Remote Provider
generateText()andgenerateObject(), nostreamText()support📚 Model Support
🧪 Comprehensive Testing
📖 Documentation
Future enhancements:
ai-services-unifiedand make all provider logic generic and delegated to provider factory instanceAdditional notes
Had to patch FastMCP library to support passing requestSampling additional params punkpeye/fastmcp#125
task_master_sampling_demo_.mp4