feat: implement MCP sampling AI SDK provider package #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Overview
Implements a new
@mcpc/ai-sdk-providerpackage that enables using MCP (Model Context Protocol) sampling capabilities through the AI SDK's standard provider interface. This allows developers to leverage AI SDK's agent capabilities with MCP servers and MCPC agents.Motivation
The AI SDK provides a powerful, standardized interface for working with language models. By implementing an MCP provider for the AI SDK, developers can:
Implementation
Core Components
Provider (
src/provider.ts)MCPProviderclass that implements the AI SDK provider patterncreateMCPProvider()factory function for easy instantiationLanguage Model (
src/language-model.ts)MCPLanguageModelimplementing AI SDK'sLanguageModelV1interfaceKey Features
✅ Full AI SDK Compliance: Implements the complete
LanguageModelV1interface✅ Type Safety: Complete TypeScript support with proper type definitions
✅ System Prompts: Support for AI SDK system messages
✅ Multi-turn Conversations: Maintains conversation history
✅ Streaming API: Returns responses through AI SDK's streaming interface
✅ Error Handling: Proper error mapping and handling
Usage Example
Integration with MCPC
The provider works seamlessly with MCPC agentic tools:
Testing
Documentation
Design Decisions
Dedicated Package: Implemented as a separate
@mcpc/ai-sdk-providerpackage per requirements, without modifying core.Streaming: MCP sampling doesn't natively support streaming, so the implementation returns the complete response as a single chunk. This is clearly documented.
Token Counting: MCP doesn't provide token counts, so usage metrics report 0. This is documented.
References
Closes #[issue-number]
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.deno.landcurl -s REDACTED(dns block)jsr.io/usr/local/lib/node_modules/deno/deno install(dns block)/usr/local/lib/node_modules/deno/deno test --allow-all packages/core/tests/(dns block)/usr/local/lib/node_modules/deno/deno test --allow-all packages/ai-sdk-provider/tests/(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.