Skip to content

Support args of custom types in dspy mcp tool #8142

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

Merged
merged 1 commit into from
Apr 30, 2025

Conversation

chenmoneygithub
Copy link
Collaborator

Currently if an MCP tool's arg is of custom type, then the tool.args doesn't reflect the json schema correctly. For example:

from mcp.server.fastmcp import FastMCP
from pydantic import BaseModel

mcp = FastMCP("test")


class Profile(BaseModel):
    name: str
    age: int


class Account(BaseModel):
    profile: Profile
    account_id: str

@mcp.tool()
def get_account_name(account: Account):
    """This extracts the name from account"""
    return account.profile.name


if __name__ == "__main__":
    mcp.run()

will have the args be like {'account': {'$ref': '#/$defs/Account'}}, which doesn't have sufficient information for the LM to generate right args. This PR fixes it by explicitly resolving the refs.

@chenmoneygithub chenmoneygithub requested a review from okhat April 30, 2025 01:41
@okhat okhat merged commit 1c27898 into stanfordnlp:main Apr 30, 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