https://anthropic.skilljar.com/introduction-to-model-context-protocol
Introducing MCP

- chat interface using llm with github mcp tools

- tool functions
- to handle all of github’s functionality. we’d have to create an incredible number of tools schemas and functions
- this is all code that we (developers) have to write test and maintain → shifts the burden of tools definition and execution onto MCP servers
- to handle all of github’s functionality. we’d have to create an incredible number of tools schemas and functions

- Q&A
- how is different from just calling a service’s api directly?
- mcp servers provide tool schema + functions
- if you want to directly call an API directly you’ll be authoring those on your own
- sounds like MCP servers and tool use are the same thing
- MCP servers provide tool schemas + functions already defined for you (kinda bigger concept)
- how is different from just calling a service’s api directly?
Hands-on MCP Servers
Normally a poject will implement either an MCP client or an MCP server(built server to use 3’rd persons to use it in agents, or client –like us– to use that service in building agents) but in this hands-on, we’re making all of it
- Server
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("DocumentMCP", log_level="ERROR")
Building an MCP server becomes much simpler when you use the official Python SDK. Instead of writing complex JSON schemas by hand, you can define tools with decorators and let the SDK handle the heavy lifting. And writes decorator
@mcp.tool(
name="read_doc_contents",
description="Read the contents of document and return it as a string"
)
@mcp.resource(
"docs://documents",
mime_type="application/json" # resource can return any type of data, give hint what we are returning
)
def list_docs() -> list[str]:
return list(docs.keys())
- Client
❯ uv run mcp_client.py [Tool(name='read_doc_contents', title=None, description='Read the contents of document and return it as a string', inputSchema={'properties': {'doc_id': {'description': 'Id of the document to read', 'title': 'Doc Id', 'type': 'string'}}, 'required': ['doc_id'], 'title': 'read_documentsArguments', 'type': 'object'}, outputSchema=None, icons=None, annotations=None, meta=None, execution=None), Tool(name='edit_documents', title=None, description='Edit a document by replacing a string in the documents content with string', inputSchema={'properties': {'doc_id': {'description': 'Id of the document to edit', 'title': 'Doc Id', 'type': 'string'}, 'old_str': {'description': 'The text to replace, Must match', 'title': 'Old Str', 'type': 'string'}, 'new_str': {'description': 'The new text', 'title': 'New Str', 'type': 'string'}}, 'required': ['doc_id', 'old_str', 'new_str'], 'title': 'edit_documentsArguments', 'type': 'object'}, outputSchema=None, icons=None, annotations=None, meta=None, execution=None)]
whats in the @… => our code converts this mention to Requst (client-side)
❯ uv run main.py
> Whats in the @report.pdf
claude didn’t used tools, when using resources(by mentioning) it directly inject the resource. So It’s same as given by the prompt
- Prompts User might have more luck if they use our thoroughly eval’d prompt instead use prompt decorator to manage prompts
{
"description": "",
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "Your goal is to reformat a document to be written with markdown syntax.\n\nThe id of the document you need to reformat is:\n<document_id>\nreport.pdf\n</document_id>\n\nAdd in headers, bullet points, tables, etc as necessary. Feel free to add in structure.\nUse the 'edit_document' tool to edit the document. After the document has been reformatted..."
}
}
]
}
focus on what is controlled by what