Skip to content

Conversation

@yaonyan
Copy link
Contributor

@yaonyan yaonyan commented Oct 6, 2025

This pull request significantly enhances the AI SDK MCP Sampling Provider examples and core implementation to support advanced tool calling, structured object generation, and improved streaming compatibility. The changes introduce new example scripts demonstrating structured data and streaming with tool calls, and update the core language model to better align with the AI SDK v2 protocol, including improved handling of tool calls/results and streaming events.

New Example Scripts and Features:

  • Added generate_object_example.ts to demonstrate generating structured objects (e.g., recipes) using the MCP Sampling Provider and AI SDK's generateObject function.
  • Added stream_text_example.ts to showcase streaming text generation and tool call handling with streamText, including a calculator tool example.

Enhancements to Existing Examples:

  • Extended generate_text_example.ts to include a new tool ("test-tool-calls") that demonstrates tool injection and execution (e.g., calculator) with AI SDK's generateText. Also removed the unused agent definition for clarity. [1] [2] [3]

Core Language Model Improvements:

  • Improved the MCPSamplingLanguageModel to:
    • Parse and emit tool calls and results as content parts, mapping them to the AI SDK v2 protocol. [1] [2]
    • Inject tool definitions and response format instructions into the system prompt as a workaround for current MCP limitations.
    • Update streaming (doStream) to emit events (text-start, text-delta, text-end, tool-call, response-metadata, finish) in the correct AI SDK order, ensuring compatibility with consumers expecting v2 protocol streams.
    • Standardize usage reporting and clean up type imports. [1] [2]

Documentation and Clarity:

  • Added and improved docstrings and comments throughout new and modified files for better developer understanding and onboarding. [1] [2] [3]

Summary of Most Important Changes:

New Example Scripts:

  • Added generate_object_example.ts for structured object generation with AI SDK and MCP Sampling Provider.
  • Added stream_text_example.ts for streaming text and tool call handling examples.

Enhanced Tool Call Support:

  • Extended generate_text_example.ts with a "test-tool-calls" tool to demonstrate tool injection and execution with AI SDK.
  • Improved parsing and emission of tool calls/results in MCPSamplingLanguageModel, mapping them to AI SDK v2 protocol. [1] [2]

Streaming Protocol Compliance:

  • Updated doStream in MCPSamplingLanguageModel to emit events in the correct AI SDK v2 order and format, including tool calls and response metadata.

Developer Experience:

  • Added detailed documentation and comments to new and modified files for clarity and onboarding. [1] [2] [3]

@yaonyan yaonyan self-assigned this Oct 6, 2025
- Removed the old `@mcpc/ai-sdk-mcp-sampling-provider` package and its README.
- Introduced `@mcpc/mcp-sampling-ai-provider` package with a new README and examples.
- Implemented core functionality for the MCP sampling provider, including language model integration.
- Added support for structured data generation and streaming text generation examples.
- Created tests for the MCP provider to ensure functionality and reliability.
- Updated Deno configuration for the new package.
@yaonyan yaonyan merged commit 7b40c28 into main Oct 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants