这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(mcp): add argument serialization for JSON compatibility #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tuannvm
Copy link
Contributor

@tuannvm tuannvm commented Jun 19, 2025

Summary

This update refactors the SerializeArgsForMCP function to improve argument serialization for MCP servers. It now recursively handles nested structures such as maps and slices, and converts complex types using JSON marshaling and unmarshaling, ensuring all arguments are in proper JSON-compatible formats before transmission.

Affected Modules

  • pkg/mcp/utils.go: serialization utility functions.
  • pkg/mcp/http_client.go, pkg/mcp/stdio_client.go: argument preparation during tool calls.

Key Details

  • Serialization Strategy:
    • Recursively serializes nested map[string]any and []any.
    • Uses JSON marshaling/unmarshaling as a fallback for complex or custom types, ensuring broad type coverage.
    • Handles primitive types directly.
  • Function Changes:
    • SerializeArgsForMCP: now performs deep serialization and type normalization.
    • serializeValue: new recursive helper function, converting values to JSON-compatible representations.
  • Error Handling: Provides informative errors during complex serialization failures.

Signed-off-by: Tommy Nguyen <tuannvm@hotmail.com>
@tuannvm tuannvm marked this pull request as ready for review June 19, 2025 13:59
@droot
Copy link
Member

droot commented Jun 20, 2025

@tuannvm This PR https://github.com/GoogleCloudPlatform/kubectl-ai/pull/366/files now relays the input schema exposed by the MCP server properly, I suspect, it will eliminate the need for this PR.

@droot
Copy link
Member

droot commented Jun 20, 2025

See this one as well https://github.com/GoogleCloudPlatform/kubectl-ai/pull/369/files, its related as well. Overall, we should have less logic between LLM and MCP exchange.

@justinsb
Copy link
Collaborator

justinsb commented Jun 20, 2025

it will eliminate the need for this PR.

I'm not sure it eliminates the need for this PR, I can imagine for some LLMs we might need to convert types? But we should do it based on the target schema I think. But maybe the latest LLMs are actually good enough that they just get the schemas right? Would love your thoughts @tuannvm ...

@tuannvm
Copy link
Contributor Author

tuannvm commented Jun 20, 2025

@droot Gotcha!

@tuannvm tuannvm closed this Jun 20, 2025
@tuannvm tuannvm reopened this Jun 20, 2025
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.

3 participants