How riemannzeta/patent_mcp_server works
Project type and purpose
• This is a backend‐only service (“Patent MCP Server”) implementing the Model Context Protocol (MCP).
• It exposes an MCP endpoint over stdio, allowing a client (Claude Desktop or any MCP client) to issue patent‐related requests.
• Internally, it wraps two external USPTO APIs: the Patent Public Search (“ppubs.uspto.gov”) and the Open Data Portal (“api.uspto.gov”).
File structure
• Top level:
• setup.py, pyproject.toml, UV config for packaging and dependency management
• src/patent_mcp_server – main Python package
• json/ & pdfs/ – sample data and PDF artifacts
• test/ – unit tests and stored responses
• src/patent_mcp_server:
• __main__.py – entry point wiring into FastMCP server
• patents.py – core MCP handlers that map incoming method calls to logic
• uspto/api_uspto_gov.py & ppubs_uspto_gov.py – thin clients for the two USPTO endpoints
• util/logging.py – shared logging setup
• json/search_query.json – sample request schema
• test/ exercises every MCP method, validating against stored JSON and PDF responses.
README for insights
• Confirms stdio transport for MCP protocol.
• Lists available methods (ppubs_search_patents, get_app_metadata, etc.).
• Clarifies dependencies on Claude Desktop (client) and on a PATENTS_MCP_SERVER_ODP_API_KEY.
• Explains role of UV for launching the server: “uv run patent-mcp-server”.
a. Main components
• Client (Claude Desktop or any MCP client)
• MCP Server Process
• Internal modules: Request Router, Handler Layer, API Clients, Logging Utility
• External USPTO services: Public Search API and Open Data Portal API
• Local resources: sample JSON, PDF cache
b. Relationships & data flow
1. Client → (stdio JSON‐RPC) → MCP Server
2. Router in __main__.py dispatches to handlers in patents.py
3. Handler invokes one of two API client modules
4. API client issues HTTP request to USPTO endpoint
5. Response flows back to handler → Router → Client over stdio
6. Logging utility records both incoming requests and external API calls
7. Tests simulate this flow using local test data
c. Architectural patterns & design principles
• Layered architecture: Transport → Routing → Business logic → External adapters
• Single‐responsibility modules: each USPTO API lives in its own adapter
• Configuration via environment (.env) and UV for reproducible environments
d. Key technologies & frameworks
• Python 3.x, FastMCP server library
• UV for dependency/version management
• Requests or HTTPX (inside API client modules)
• pytest or built‐in test runner for unit tests