yellowsubmarine372

Anthropic, Introduction to Model Context Protocol

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

Introducing MCP

1st_image

2nd_image

3rd_image

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

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())

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

{
  "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..."
      }
    }
  ]
}

4th_image focus on what is controlled by what

← all posts