Skip to content

Conversation

@Adebesin-Cell
Copy link
Member

@Adebesin-Cell Adebesin-Cell commented Dec 1, 2025

Closes #406 when this PR merged

This PR focuses on resolving type-related issues within the Model Context Protocol (MCP) integration by updating the core SDK and refining the handling of MCP tools and content. The changes enhance the stability and robustness of the MCP client and tool adapters, ensuring better compatibility with the updated SDK and more reliable data conversion processes.

Key Changes:

  • SDK Update: Upgraded @modelcontextprotocol/sdk to version ^1.23.0 to leverage the latest features and fixes.
  • MCP Client Transport: Replaced SSEClientTransport with StreamableHTTPClientTransport to improve streaming capabilities and type handling in HTTP communication.
  • Improved Type Safety for MCP Tools: Added stricter type checks and fallback mechanisms in McpToolAdapter to safely handle tool metadata (metadata and _meta) and ensure the execute method exists and is a function.
  • Robust MCP Content Conversion: Enhanced McpSamplingHandler to better convert various MCP content types (arrays, tool_use, tool_result) to ADK parts, along with a safeText helper for improved type safety.
  • New Utility Script: Added a clean-locks script to the root package.json for easily removing lock files (pnpm-lock.yaml, package-lock.json, yarn.lock) across the repository.

Related Issue

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Code refactoring (type safety and robustness improvements)
  • Performance improvement (improved streaming and conversion handling)

How Has This Been Tested?

  • Verified MCP client and tool adapter functionality with updated SDK.
  • Tested conversion of multiple MCP content types to ADK parts.
  • Ran the clean-locks script to ensure proper removal of lock files.

Checklist

  • Code follows project style guidelines
  • Documentation updated where necessary
  • Tests added/verified for updated functionality
  • No new warnings or errors introduced

Additional Notes

These changes primarily target type safety, data conversion reliability, and SDK compatibility for the MCP integration.

@changeset-bot
Copy link

changeset-bot bot commented Dec 1, 2025

🦋 Changeset detected

Latest commit: 45645aa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@iqai/adk Patch
@iqai/adk-cli Patch

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

@vercel
Copy link
Contributor

vercel bot commented Dec 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
adk-typescript-docs Ready Ready Preview Dec 2, 2025 4:10pm
adk-web Ready Ready Preview Dec 2, 2025 4:10pm

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Adebesin-Cell, 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 primarily focuses on resolving type-related issues within the Model Context Protocol (MCP) integration by updating the core SDK and refining how MCP tools and content are handled. The changes aim to enhance the stability and robustness of the MCP client and tool adapters, ensuring better compatibility with the updated SDK and more reliable data conversion processes.

Highlights

  • SDK Update: The @modelcontextprotocol/sdk dependency has been updated to version ^1.23.0, bringing in the latest features and fixes from the SDK.
  • MCP Client Transport: The SSEClientTransport has been replaced with StreamableHTTPClientTransport in the MCP client, likely improving streaming capabilities and type handling for HTTP-based communication.
  • Improved Type Safety for MCP Tools: Enhanced type checks and fallback mechanisms have been added to McpToolAdapter for handling tool metadata (metadata and _meta) and ensuring the execute method exists and is a function before invocation, preventing potential runtime errors.
  • Robust MCP Content Conversion: The McpSamplingHandler now includes more comprehensive logic for converting various MCP content types (including arrays, tool_use, and tool_result) to ADK parts, along with a safeText helper for better type robustness.
  • New Utility Script: A new clean-locks script has been added to the root package.json to easily remove various lock files (pnpm-lock.yaml, package-lock.json, yarn.lock) across the repository.
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 focuses on fixing type errors, primarily by updating the @modelcontextprotocol/sdk dependency and improving type safety across the codebase. The changes are solid, particularly the more robust handling of different data structures and property existence checks in create-tool.ts and sampling-handler.ts. The refactoring of convertMcpContentToADKParts to manage various content types is a significant improvement. I've included a few suggestions to further enhance correctness and type safety.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Adebesin Tolulope (Lope) <[email protected]>
@MarvelNwachukwu
Copy link
Contributor

@claude review

@claude
Copy link
Contributor

claude bot commented Dec 2, 2025

Claude finished @MarvelNwachukwu's task —— View job


Code Review of PR #402: fix: mcp type errors

I've completed a comprehensive review of the MCP type error fixes in this PR. Overall, the changes improve type safety and error handling, though there are some areas that could benefit from additional improvements.

Todo List

  • Read and analyze the key changed files
  • Review type safety improvements in McpToolAdapter
  • Review MCP content conversion logic in sampling-handler
  • Check SDK update and transport changes
  • Provide comprehensive review feedback

Review Summary

This PR successfully addresses several type safety issues in the MCP integration and upgrades the SDK to v1.23.0. The changes are well-structured and improve the robustness of the codebase.

Positive Changes

1. SDK Update (package.json:38)

Good: Updated @modelcontextprotocol/sdk from unspecified to ^1.23.0, bringing in latest features and fixes.

2. Transport Improvement (client.ts:3,126)

Good: Replaced SSEClientTransport with StreamableHTTPClientTransport for better streaming capabilities and type handling.

3. Enhanced Error Handling

Good: Comprehensive error handling in McpSamplingHandler with proper validation using MCP schemas and detailed error messages.

Issues and Improvements Needed

1. Type Safety Issue in McpToolAdapter (create-tool.ts:73-77)

Issue: The metadata extraction logic has potential type safety issues:

if ("metadata" in mcpTool && typeof mcpTool.metadata === "object") {
    metadata = mcpTool.metadata as McpToolMetadata;
} else if (mcpTool._meta && typeof mcpTool._meta === "object") {
    metadata = mcpTool._meta as McpToolMetadata;
}

Problems:

  1. typeof mcpTool.metadata === "object" returns true for null, which could cause runtime errors
  2. The mcpTool._meta check doesn't verify it's actually an object before casting

Recommended Fix:

if (mcpTool.metadata && typeof mcpTool.metadata === "object") {
    metadata = mcpTool.metadata as McpToolMetadata;
} else if (mcpTool._meta && typeof mcpTool._meta === "object") {
    metadata = mcpTool._meta as McpToolMetadata;
}

2. Incomplete Data Handling in sampling-handler.ts (lines 224-238)

Issue: The code for handling image and audio content creates parts even when data is missing:

case "image":
case "audio": {
    // ... validation code shows missing data problem
    if (!hasData) {
        this.logger.warn(`Missing or invalid 'data' for ${mcpContent.type} content.`);
        return [...parts, { text: `[${mcpContent.type.toUpperCase()} CONTENT MISSING DATA]` }];
    }

Assessment: ✅ Good - This was actually handled correctly! The code properly validates data exists and provides a meaningful fallback when it's missing. I see this was already addressed in response to the review comments.

3. Debugging Information (sampling-handler.ts:187)

Minor Issue: The log message could be more informative:

`Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${Array.isArray(mcpMessage.content) ? "array" : (mcpMessage.content as any)?.type ?? "unknown"}`,

This provides better debugging information than logging the object directly.

Security Assessment

Security: No security concerns identified. The code follows defensive programming practices with proper input validation and error handling.

Type Safety Assessment

Overall: Good improvement in type safety with a few minor issues to address.

  • ✅ Proper use of Zod schemas for validation
  • ✅ Comprehensive error handling with custom error types
  • ✅ Safe type casting with runtime checks
  • ⚠️ Minor improvement needed in metadata extraction logic

Performance Considerations

Performance: The changes should have minimal performance impact. The StreamableHTTPClientTransport should actually improve performance for streaming scenarios.

Final Recommendation

APPROVE with minor suggestions. This PR successfully addresses the stated type errors and improves the robustness of the MCP integration. The main issue to address is the metadata extraction logic in McpToolAdapter, but this is a minor fix that doesn't block the overall improvement this PR provides.

The code follows good TypeScript practices, includes comprehensive error handling, and the SDK update brings valuable improvements to the MCP integration.


Copy link
Contributor

@MarvelNwachukwu MarvelNwachukwu left a comment

Choose a reason for hiding this comment

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

MCP Example runs fine locally, might be worth checking Claude's comments for minor suggestions before merging

@Adebesin-Cell
Copy link
Member Author

MCP Example runs fine locally, might be worth checking Claude's comments for minor suggestions before merging

Most of the issues are resolved already

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.

Fix issues with releases failing on ADK

3 participants