Skip to content

feature: MCPServer object should provide a GetTool() method #565

@duaraghav8

Description

@duaraghav8

Problem Statement

It is easy to add a tool to an MCPServer object by running server.AddTool(tool, handler) where tool is mcp.NewTool("name", ...ToolOption).

But there is no way to get back a particular tool from the mcp server given its name.

So it is inconvenient to have to keep track of the tools separately.

Proposed Solution

Add a convenience method to the MCPServer object: server.GetTool("name") (*Tool, error).
If I specify the name, it can return the Tool object that was originally added to it.

Example Usage

       mcpServer := server.NewMCPServer(
		"my-tools",
		"1.0.0",
		server.WithToolCapabilities(true),
	)

	echoTool := mcp.NewTool(
		"echo",
		mcp.WithDescription("echoes back your message"),
		mcp.WithString(
			"message",
			mcp.Description("Your message"),
			mcp.Required(),
		),
	)
	mcpServer.AddTool(echoTool, handleEchoToolCall)

        // Now, get back the Tool object in some other part of the code
        tool, err := mcpServer.GetTool("echo")

Alternatives/Workarounds Considered

Currently, I have to maintain a separate mapping of name to the Tool object - map[string]*Tool
Its much cleaner if the library provides this mapping.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions