AI Hints
Home›MCP Tutorial›Agents over MCP
MCP · Lesson 60 of 120

Choosing Tools

When there are many.

⏱ 2 min read▶ Video at 53:26🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

Connect ten servers, and you might have a hundred tools. Every tool definition costs tokens, and too many choices confuse the model. Good hosts give the model only the tools it needs.

Choosing Tools
From the video: Choosing Tools
  • Many servers
  • Many tools
  • Give only what's needed

Filtering tools

We keep an allow list of tool names for this assistant. Only matching tools are passed to the model. Run it. Only the order tool is kept, out of the server's two.

filter_tools.pypython
import asyncio
from mcp import Client
from mcp_tools import load_tools
from northwind import mcp

ALLOWED = {"order_status"}

async def main():
    async with Client(mcp) as client:
        every = await load_tools(client)
        chosen = [t for t in every if t.name in ALLOWED]
        print(len(every), "tools on the server ->", [t.name for t in chosen])

asyncio.run(main())
Output
2 tools on the server -> ['order_status']
Also uses northwind.py
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError

mcp = MCPServer("northwind")
ORDERS = {1042: "shipped", 1043: "packing", 1044: "delivered"}

@mcp.tool()
def order_status(order_id: int) -> str:
    """Look up the status of a Northwind order by its number."""
    if order_id not in ORDERS:
        raise ToolError(f"Order {order_id} not found")
    return ORDERS[order_id]

@mcp.tool()
def delivery_cost(order_total: float) -> str:
    """UK delivery cost for an order total in pounds."""
    return "free" if order_total >= 50 else "£4.99"

@mcp.resource("policy://returns")
def returns_policy() -> str:
    """Northwind's returns policy."""
    return "You can return any unused item within 30 days of delivery."

@mcp.prompt()
def support_reply(question: str) -> str:
    """Draft a polite reply to a customer."""
    return f"Write a short, polite reply to this Northwind customer: {question}"

if __name__ == "__main__":
    mcp.run()
Also uses mcp_tools.py
from langchain_core.tools import StructuredTool

def to_langchain(client, t):
    async def call(**args):
        result = await client.call_tool(t.name, args)
        return result.content[0].text
    return StructuredTool(name=t.name, description=t.description,
                          args_schema=t.input_schema, coroutine=call)

async def load_tools(client):
    listed = await client.list_tools()
    return [to_langchain(client, t) for t in listed.tools]

Ways to choose

Use an allow list per assistant. Group tools by task, and load only the group you need. Or search tool descriptions, and pick the closest few for each question.

keyvalue
Allow listper assistant
Groupsby task
Searchclosest tools
Fewer toolsbetter choices

Summary

Give each assistant only the tools it needs, with an allow list, groups, or search. Next, answering elicitation on the client.

Key takeaways
  • Allow list
  • Groups
  • Fewer tools
Next up: Answering Elicitation — the client side