This section briefly explains what MCP is and why it’s useful. Before describing MCP, it helps to understand tool-calling first — MCP is built on top of it.
Tool-calling Tool-calling is a capability that lets an AI model (like an LLM) interact with the outside world by invoking external functions or APIs.
Here’s a simple example of tool-calling in Python with two tools, bash_tool and web_search:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 # mock tools def bash_tool(command: str) -> str: """Run a shell command and return its output.""" return "index.html main.py styles.css README.md" if command == "ls" else "Done" def web_search(query: str) -> str: """Search the web and return the results.""" return f"Search results for '{query}': Found documentation." tools = {"bash_tool": bash_tool, "web_search": web_search} # Simulates the AI picking a tool based on keywords def mock_llm(query): if "file" in query or "list" in query: return {"tool": "bash_tool", "arguments": {"command": "ls"}} return {"tool": "web_search", "arguments": {"query": query}} while True: user_query = input("User: > ") if user_query.lower() in ["exit", "quit"]: print("Goodbye!") break # Step 1: Get tool choice from LLM decision = mock_llm(user_query) tool_name, args = decision["tool"], decision["arguments"] print(f"AI wants to call: {tool_name}({args})") # Step 2 & 3: execute the tool and print the output tool_output = tools[tool_name](**args) print(f"Tool Output: {tool_output}\n") That’s tool-calling in a nutshell: the model picks a tool (e.g. web_search or bash_tool) and supplies the right arguments (e.g. query: "who won the 2022 World Cup"), the tool or API is executed — locally or remotely — and the model reads back the result.
...