feat: add support for MCP Sampling as AI provider (#863)
* 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 (#913) (#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/claude-task-master#913 * docs: fix gemini-cli authentication documentation (#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 (#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>
This commit is contained in:
@@ -23,6 +23,14 @@ export class AnthropicAIProvider extends BaseAIProvider {
|
||||
this.name = 'Anthropic';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the Anthropic API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'ANTHROPIC_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an Anthropic client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
|
||||
@@ -12,6 +12,14 @@ export class AzureProvider extends BaseAIProvider {
|
||||
this.name = 'Azure OpenAI';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the Azure OpenAI API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'AZURE_OPENAI_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates Azure-specific authentication parameters
|
||||
* @param {object} params - Parameters to validate
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { generateObject, generateText, streamText } from 'ai';
|
||||
import { log } from '../../scripts/modules/index.js';
|
||||
import { log } from '../../scripts/modules/utils.js';
|
||||
|
||||
/**
|
||||
* Base class for all AI providers
|
||||
@@ -96,6 +96,24 @@ export class BaseAIProvider {
|
||||
throw new Error('getClient must be implemented by provider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the API key is required
|
||||
* @abstract
|
||||
* @returns {boolean} if the API key is required, defaults to true
|
||||
*/
|
||||
isRequiredApiKey() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the required API key environment variable name
|
||||
* @abstract
|
||||
* @returns {string|null} The environment variable name, or null if no API key is required
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
throw new Error('getRequiredApiKeyName must be implemented by provider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates text using the provider's model
|
||||
*/
|
||||
|
||||
@@ -8,6 +8,19 @@ export class BedrockAIProvider extends BaseAIProvider {
|
||||
this.name = 'Bedrock';
|
||||
}
|
||||
|
||||
isRequiredApiKey() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the required API key environment variable name for Bedrock.
|
||||
* Bedrock uses AWS credentials, so we return the AWS access key identifier.
|
||||
* @returns {string} The environment variable name
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'AWS_ACCESS_KEY_ID';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override auth validation - Bedrock uses AWS credentials instead of API keys
|
||||
* @param {object} params - Parameters to validate
|
||||
|
||||
@@ -15,6 +15,14 @@ export class ClaudeCodeProvider extends BaseAIProvider {
|
||||
this.name = 'Claude Code';
|
||||
}
|
||||
|
||||
getRequiredApiKeyName() {
|
||||
return 'CLAUDE_CODE_API_KEY';
|
||||
}
|
||||
|
||||
isRequiredApiKey() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override validateAuth to skip API key validation for Claude Code
|
||||
* @param {object} params - Parameters to validate
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import { generateObject, generateText, streamText } from 'ai';
|
||||
import { parse } from 'jsonc-parser';
|
||||
import { BaseAIProvider } from './base-provider.js';
|
||||
import { log } from '../../scripts/modules/index.js';
|
||||
import { log } from '../../scripts/modules/utils.js';
|
||||
|
||||
let createGeminiProvider;
|
||||
|
||||
@@ -652,4 +652,12 @@ Generate ${subtaskCount} subtasks based on the original task context. Return ONL
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
getRequiredApiKeyName() {
|
||||
return 'GEMINI_API_KEY';
|
||||
}
|
||||
|
||||
isRequiredApiKey() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,14 @@ export class VertexAIProvider extends BaseAIProvider {
|
||||
this.name = 'Google Vertex AI';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the required API key environment variable name for Google Vertex AI.
|
||||
* @returns {string} The environment variable name
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'GOOGLE_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates Vertex AI-specific authentication parameters
|
||||
* @param {object} params - Parameters to validate
|
||||
|
||||
@@ -12,6 +12,14 @@ export class GoogleAIProvider extends BaseAIProvider {
|
||||
this.name = 'Google';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the Google API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'GOOGLE_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Google AI client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
|
||||
@@ -39,4 +39,16 @@ export class OllamaAIProvider extends BaseAIProvider {
|
||||
this.handleError('client initialization', error);
|
||||
}
|
||||
}
|
||||
|
||||
isRequiredApiKey() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the required API key environment variable name for Ollama.
|
||||
* @returns {string} The environment variable name
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'OLLAMA_API_KEY';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,14 @@ export class OpenAIProvider extends BaseAIProvider {
|
||||
this.name = 'OpenAI';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the OpenAI API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'OPENAI_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an OpenAI client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
|
||||
@@ -12,6 +12,14 @@ export class OpenRouterAIProvider extends BaseAIProvider {
|
||||
this.name = 'OpenRouter';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the OpenRouter API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'OPENROUTER_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an OpenRouter client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
|
||||
@@ -12,6 +12,14 @@ export class PerplexityAIProvider extends BaseAIProvider {
|
||||
this.name = 'Perplexity';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the Perplexity API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'PERPLEXITY_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a Perplexity client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
|
||||
@@ -12,6 +12,14 @@ export class XAIProvider extends BaseAIProvider {
|
||||
this.name = 'xAI';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the environment variable name required for this provider's API key.
|
||||
* @returns {string} The environment variable name for the xAI API key
|
||||
*/
|
||||
getRequiredApiKeyName() {
|
||||
return 'XAI_API_KEY';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns an xAI client instance.
|
||||
* @param {object} params - Parameters for client initialization
|
||||
|
||||
Reference in New Issue
Block a user