Skip to content

Conversation

@amondnet
Copy link

@amondnet amondnet commented Jan 6, 2026

Description

This PR adds Model Context Protocol (MCP) tools support to the Anthropic plugin, enabling the use of MCP servers and toolsets with Claude models in the Genkit framework.

Key Features

  • MCP tool type definitions (McpServerConfigSchema, McpToolsetSchema) for type-safe configuration
  • Handlers for mcp_tool_use and mcp_tool_result response blocks
  • Request body extension to include mcp_servers and mcp_toolsets configuration
  • Enabled mcp-client-2025-11-20 beta header for MCP protocol support

MCP Server Configuration

Based on the Anthropic MCP Connector documentation:

Property Type Required Description
type string Yes Currently only "url" is supported
url string Yes The URL of the MCP server. Must start with https://
name string Yes A unique identifier for this MCP server. Must be referenced by exactly one MCPToolset in the tools array.
authorization_token string No OAuth authorization token if required by the MCP server. See MCP specification.

Example Usage

const response = await ai.generate({
  model: anthropic.model('claude-sonnet-4-5'),
  prompt: 'Search for TypeScript files in my project',
  config: {
    apiVersion: 'beta',
    mcp_servers: [
      {
        type: 'url',
        url: 'https://your-mcp-server.com/v1',
        name: 'filesystem',
        authorization_token: process.env.MCP_TOKEN, // Optional
      },
    ],
    mcp_toolsets: [
      {
        type: 'mcp_toolset',
        mcp_server_name: 'filesystem',
        default_config: { enabled: true },
      },
    ],
  },
});

Checklist (if applicable):

- Add MCP server and toolset configuration schemas (McpServerConfigSchema, McpToolsetSchema)
- Enable mcp-client-2025-11-20 beta header for MCP support
- Add handlers for mcp_tool_use and mcp_tool_result response blocks
- Update request body to include mcp_servers and mcp_toolsets configuration
- Add comprehensive documentation with usage examples in README
- Add 7 new tests covering MCP functionality and configuration
@github-actions github-actions bot added docs Improvements or additions to documentation js labels Jan 6, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @amondnet, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Anthropic plugin by integrating Model Context Protocol (MCP) tools. This allows Claude models to leverage external, server-managed tools, expanding their capabilities beyond their inherent functions. The changes involve defining new configuration schemas, updating the request and response handling logic to support MCP-specific blocks, and activating the necessary beta API header. This feature provides developers with greater flexibility in building applications that require Claude to interact with external services through a standardized protocol.

Highlights

  • MCP Tools Integration: Adds Model Context Protocol (MCP) tools support to the Anthropic plugin, enabling Claude models to use external MCP servers and toolsets within the Genkit framework.
  • Type Definitions: Introduces new Zod schemas (McpServerConfigSchema, McpToolsetSchema) and corresponding TypeScript types for type-safe configuration of MCP servers and toolsets.
  • Response Handling: Implements handlers for mcp_tool_use and mcp_tool_result response blocks, allowing the plugin to correctly process and expose these tool interactions in Genkit's format.
  • Request Configuration: Extends the request configuration to include mcp_servers and mcp_toolsets, which are then merged with any existing tools before being sent to the Anthropic API.
  • Beta API Activation: Enables the mcp-client-2025-11-20 beta header, which is necessary for supporting the new MCP protocol with Anthropic models.
  • Comprehensive Testing: Includes 7 new MCP-specific unit tests to verify the correct handling of MCP stream events, content blocks, and request body construction.
  • Updated Documentation: The README.md has been updated with detailed documentation and usage examples for configuring and utilizing MCP tools within the Anthropic plugin.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for Model Context Protocol (MCP) tools to the Anthropic plugin. The changes are well-structured, including new type definitions for MCP configuration, handlers for MCP-related response blocks, and updates to the request body generation. The feature is also well-documented in the README and thoroughly tested.

My main feedback is to refactor some duplicated code to improve maintainability. Overall, this is a great addition to the plugin.

…dling

- Add logging for MCP tool errors (is_error: true)
- Add [ERROR] prefix to MCP tool result text when execution fails
- Add URL HTTPS validation to McpServerConfigSchema
- Add MCP server name uniqueness validation
- Add mcp_server_name reference validation (toolset must reference existing server)
- Add runtime type checks for MCP content block fields
- Add edge case tests for streaming, fallback scenarios
- Document anthropicMcpToolResult structure in README
@amondnet
Copy link
Author

amondnet commented Jan 6, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively adds support for MCP tools to the Anthropic plugin, including new type definitions, request/response handlers, and comprehensive validation. The code is well-structured, and the addition of extensive unit tests is commendable. I have a few suggestions for improvement: one to simplify an example in the documentation, another to enhance type safety in the response handling, and a final one to make the new tests more robust by mocking the correct logger. Overall, this is a great contribution.

Extract duplicated config and tools preparation logic into a private
helper method to improve maintainability (DRY principle).
… one toolset

Per Anthropic MCP Connector documentation, each MCP server must be
referenced by exactly one MCPToolset in the tools array.

- Add validation: server not referenced by any toolset → error
- Add validation: server referenced by multiple toolsets → error
- Add 7 new tests for MCP configuration validation
- Update README with new validation rule

Co-authored-by:
…docs

Update MCP schemas to use Zod .describe() for consistency with codebase:
- name: clarify must be referenced by exactly one MCPToolset
- authorization_token: specify OAuth token
- mcp_server_name: clarify must match server in mcp_servers array
- defer_loading: explain tool description behavior
- default_config/configs: clarify override precedence

Co-authored-by:
- Simplify conditional check in README.md (find already ensures truthy)
- Add typeof check for tool_use_id type safety
- Use logger.warn mock instead of console.warn in tests
@amondnet
Copy link
Author

amondnet commented Jan 6, 2026

Code Review Suggestions Applied

Applied suggestions from @gemini-code-assist in 3f63fae75:

1. README.md - Simplify conditional check

✅ Changed if (mcpToolResult?.custom?.anthropicMcpToolResult) to if (mcpToolResult) since find already ensures truthy value.

2. beta.ts - Type safety for tool_use_id

✅ Added typeof check for tool_use_id consistent with how is_error is handled.

3. beta_runner_test.ts - Use logger mock

✅ Changed from console.warn mock to logger.warn mock to match the actual implementation.

@gemini-code-assist
Copy link
Contributor

Thanks for implementing the suggestions, @amondnet! It's great to see these improvements incorporated into the pull request. The changes you've made, especially regarding the conditional check simplification, type safety for tool_use_id, and the logger mock, align perfectly with the feedback provided. Excellent work!

@amondnet amondnet marked this pull request as ready for review January 6, 2026 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation js

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant