Using tools in mcp-golang
The Model Context Protocol (MCP) allows servers to expose tools that can be invoked by language models. Tools enable models to interact with external systems, such as querying databases, calling APIs, or performing computations. Each tool is uniquely identified by a name and includes metadata describing its schema.In MCP golang, you can register a tool with the MCP server using the
RegisterTool
function. This function takes a name, a description, and a handler that will be called when the tool is called by a client.
Here’s an example of spinning up a server that has a single tool:
RegisterTool
function takes a name, a description, and a handler that will be called when the tool is called by a client. The information you pass to the RegisterTool
function is used to generate the tool schema.
When a client calls a tool, the server will send the arguments to the handler function.*mcp_golang.ToolResponse
and an error
. If you pass back an error, mcp-golang will take care of serializing it and passing it back to the client.jsonschema:"required"
tag.jsonschema:"required"
tag.jsonschema:"description"
tag to add a description to the argument.