2 ms·
How does the LLM know that it can use the factor tool to factor integers? Just by looking at the string "factor an integer"?
by amelius 1y ago
How does the LLM know that it can use the factor tool to factor integers? Just by looking at the string "factor an integer"?
- manojlds 1y agoYup this is what the tools response for the mcp server looks like: { tools: [ 0: { name: "factor" description: "Factor an integer" inputSchema: { ... } 4 items } ] }
- snek_case 1y agoThey give it a list of tool commands it can use in the context I believe.
- svat 1y agoYes, and I believe this is what the article is referring to when it says “a stochastic black box that communicates through a complex web of JSON schemas attached to docstring annotations”. Specifically, in the function definition: @mcp.tool() def factor(a: int) -> int: """Factor an integer""" return factor_number(a) the decorator `@mcp.tool()` does something behind the scenes to set up the right thing using the docstring of the function. The documentation and source code seem to be: - (official SDK): https://github.com/modelcontextprotocol/python-sdk/blob/e80c0150e1c2e45f66195d3cf7d209be31ce6e5d/src/mcp/server/fastmcp/server.py#L344 https://github.com/modelcontextprotocol/python-sdk/blob/e80c... -> using the function's docstring: https://github.com/modelcontextprotocol/python-sdk/blob/e80c0150e1c2e45f66195d3cf7d209be31ce6e5d/src/mcp/server/fastmcp/tools/base.py#L55 https://github.com/modelcontextprotocol/python-sdk/blob/e80c... - (v2?): https://gofastmcp.com/servers/tools#the-%40tool-decorator https://gofastmcp.com/servers/tools#the-%40tool-decorator and https://github.com/jlowin/fastmcp/blob/998de22a6e76fc8ae323e829c38143c910ff57db/src/fastmcp/server/server.py#L485 https://github.com/jlowin/fastmcp/blob/998de22a6e76fc8ae323e... -> using the function's docstring: https://github.com/jlowin/fastmcp/blob/998de22a6e76fc8ae323e829c38143c910ff57db/src/fastmcp/tools/tool.py#L77 https://github.com/jlowin/fastmcp/blob/998de22a6e76fc8ae323e...