patentref-mcp is an MCP server for the PatentRef API (https://patentref.io), a PatentsView-compatible API for US patents. Its 19 read-only tools give an agent a US patent's claim tree with element segmentation, antecedent links and character offsets (built by deterministic code), a patent brief that fits a token budget, the expiry and maintenance-fee status record, search over US grants from 1976 to now, patents similar to a text, patent office rules with their official sources, and (experimental, S1-D) the problem a patent states and the parts its claims name, each quoted with its place in the text, with the patents whose claims name the same parts. In plan mode it serves two tools instead: one that searches the API's OpenAPI spec and one that runs a short plan of GET requests, so the tool list costs a few hundred tokens instead of a few thousand.
The server runs on your own machine. Your MCP client starts it as a local process and talks to it over stdio, the default. Each tool call becomes one HTTPS request from your machine to the PatentRef API (https://patentref.io) with the key from your environment, and the tool returns the API's JSON as the API sent it. There is no hosted MCP endpoint for this server: you run it yourself.
patentref-mcp --http is for MCP clients that connect to a URL instead of starting a process. It serves the same tools as streamable HTTP from your machine, at http://127.0.0.1:8787/mcp by default (--host and --port change the address). The requests to the API still go out from your machine with your key, so anyone who can reach that address can use your key's allowance: keep the default 127.0.0.1 unless you mean other machines to reach it.
pip install patentref-mcp
export PATENTREF_API_KEY=... # a key from https://patentref.io/api/v1/meta/signup/
patentref-mcp # stdio, what most MCP clients start
patentref-mcp --http --port 8787 # streamable HTTP at http://127.0.0.1:8787/mcp
PATENTREF_MCP_MODE=plan patentref-mcp # plan mode: search_api and run_plan in place of the 19 tools
Claude Desktop (claude_desktop_config.json):
{"mcpServers": {"patentref": {"command": "patentref-mcp", "env": {"PATENTREF_API_KEY": "..."}}}}Add "PATENTREF_MCP_MODE": "plan" to env for plan mode.
Environment: PATENTREF_API_KEY (sent by every tool but build_facts, search_disclosures and search_api), PATENTREF_BASE (default https://patentref.io), PATENTREF_TIMEOUT (seconds, default 30), PATENTREF_MCP_MODE (plan for plan mode; unset for the 19 tools), PATENTREF_MCP_CACHE (the folder where plan mode keeps its copy of the API spec; default your user cache folder).
A free key allows 1,000 requests a month and 45 a minute. Each call of a keyed tool is one request, and so is each HTTP request run_plan sends; answers 400 and 404 count too, 403 and 429 do not. build_facts, search_disclosures and search_api send no key.
Check an install: python -m patentref_mcp.smoke 10000364 starts the server over stdio, lists its tools, makes two tool calls and prints the transcript. patentref-mcp --version prints the version.
-
check_patent_status: Get the expiry and maintenance-fee status record of one granted US patent: status (active, expired_term, expired_fee_nonpayment, withdrawn or unknown), basis, reinstatement_possible, as_of, data_version, permalink, a one-sentence
plainstatement to quote, and next_steps; record facts, not a legal opinion. For many patents use search_patents with the "lapse" fields; with the claims, get_patent_brief. -
search_patents: Search granted US patents by field values with the PatentSearch v1 grammar and return matching rows a page at a time: by title words, dates, CPC class, assignee, inventor or other fields. Operators: _eq, _neq, _gt, _gte, _lt, _lte, _begins, _contains, _text_all, _text_any, _text_phrase, _and, _or, _not; dotted names reach nested fields; the "lapse" field group adds expiry_status, expiry_date_estimated, expiry_basis, reinstatement_possible, fee_status and lapse_date. Fields and grammar: https://patentref.io/llms-full.txt. To rank by a passage of text use similar_patents; for one number, check_patent_status.
-
similar_patents: Rank granted US patents by how close their title and abstract are to a passage of text (full-text bm25, searched with the text's rarest words) and return the n nearest with data_version and as_of: a record of what the data holds, not a search opinion. For exact filters such as dates, classes or names use search_patents; for patents whose claims name the same parts, get_same_part_links.
-
get_claim_tree: Get every claim of one granted US patent as a tree parsed from the published claim text: per claim its number, category, dependency, preamble, transition, elements, term mentions (each "the" or "said" phrase linked to its earlier mention), claim references and flags, with structure_version, data_version, text_data_version and as_of; every part has start and end offsets into its claim's text. Flags are notes on the text, not conclusions about the claims; no claim text answers 404. For a shorter answer within a token budget use get_patent_brief.
-
get_patent_brief: Get a brief of one granted US patent cut to fit a token budget, in a fixed order: identity and dates, the status record, each independent claim as its elements with offsets, one line per dependent claim, and the claim term keys. truncated and omitted say what was left out; tokens gives its size, never over max_tokens. Every claim and element has an anchor: page + "#" + anchor opens it on the record page. For all claims in full use get_claim_tree.
-
get_patent_units: Get the S1-D units of one granted US patent (experimental): the parts its claims name (Component, the part in normal form) and the problem it states (StatedProblem, its own sentence or clause found by a named cue rule), each with a locator {patent_id, field, sequence, start, end}. none_found means the rules found no such sentence, not that the patent has none; answers say experimental true and name s1d_version. For patents naming the same parts use get_same_part_links; to read a locator, locate_text.
-
get_same_part_links: Get the granted US patents whose claims name the same parts as one patent (S1-D names_same_part, experimental), ranked by shared parts, then by fewer patents naming those parts, then by patent number, a page at a time; each link lists up to 10 shared parts with their quotes and locators in both patents. A link says only that both patents' claims name these part words. For one patent's own parts use get_patent_units; to rank patents by a passage of text, similar_patents.
-
locate_text: Get the text at one S1-D locator (experimental): the field of one granted US patent at sequence, from start to end, up to 2,000 characters. Use it to quote or check a unit or shared part from get_patent_units, get_same_part_links or search_units; for whole claims use get_claim_tree.
-
search_units: Search S1-D units across granted US patents (experimental) in the PatentsView grammar: q names patent_id (a value or a list of up to 100) or part (in normal form), and type, cue and section filter it; plain values, _eq, and _and or _or on one field. Each row is a unit with its text and locator; total_hits_exact and budget_reached say how far the count goes. For one patent use get_patent_units; for ranked links between patents, get_same_part_links.
-
rep_required: List the representation rules of a patent office: whether and when an applicant must act through a registered agent, each row with its official source URL and a verbatim quote. For fees use fee_schedule; for time limits, route_windows; for the offices and acts, rules_index.
-
fee_schedule: List the official fees of a patent office in force on a date: filing, search, examination, grant, renewal and other fees with amounts, currency and entity tiers as the cited schedule prints them, each row with its official source URL and a verbatim quote; a row is in force when effective_from <= as_of < effective_to. For agent rules use rep_required; for time limits, route_windows.
-
route_windows: List the generic time windows of a patent office, such as the PCT national phase time limit in months from the priority date, each row with its official source URL and a verbatim quote. It never computes a last day for an application and takes no application number or date. For fees use fee_schedule; for PPH routes, pph_routes.
-
pph_routes: List the Patent Prosecution Highway (PPH) rows of to_office whose cited source names from_office as a partner office, each with its official source URL and a verbatim quote, and to_office_pph_rows, the number of PPH rows held for to_office; an empty list means no PPH row of to_office names from_office. For time limits use route_windows.
-
ai_use_statement_required: List the rows on whether a patent office requires a statement on the use of AI, each with its official source URL and a verbatim quote; an empty answer means the data holds no cited rule for that office, and nothing follows from its absence. For the other rules of an office use rep_required, fee_schedule or grace_period.
-
grace_period: List what the cited law of a patent office says about disclosures made before filing (the grace period), each row with its official source URL and a verbatim quote; citations only, it does not say whether a disclosure falls inside the period. For dated public disclosures in the PatentRef registry use search_disclosures; for other time limits, route_windows.
-
rules_changelog: List the releases of the patent office rules data from newest to oldest, each with its version, date and the rows it added, closed, changed or removed. For the current version, the offices and the vocabulary use rules_index.
-
rules_index: Describe the patent office rules data: its version and as_of date, the offices it holds with their row counts by rule kind, each rules tool with its parameters, and the act vocabulary. Call it before the other rules tools to learn the offices and acts; for the history of changes use rules_changelog. Takes no arguments.
-
build_facts: Get the facts of the patent data build the API serves now: data_version, as_of, refreshed_at, the snapshot hash, superseded versions and the table delta. Use it to cite or check which data an answer came from; for patents use search_patents, for rules rules_index. Takes no arguments.
-
search_disclosures: Search the public records of the PatentRef registry (dated technical disclosures) whose title or abstract match q, newest to oldest, up to 20; each carries its permalink (https://patentref.io/r/ and the record's id), server_time, bundle_hash and proof_status, with the submitter's text inside user_content as entered. A record shows what was published and when, not a patent or an opinion. To find patents use search_patents or similar_patents.
Every tool is read only and carries the MCP annotations readOnlyHint, idempotentHint and openWorldHint. Each description ends with whether the tool needs PATENTREF_API_KEY; the server's instructions say once what a key allows and how errors come back. An error from the API comes back as the tool's error text: the HTTP status and the API's X-Status-Reason. The server does not retry. The key goes only in the X-Api-Key header: a call whose arguments hold the key, in any letter case, is not sent, and an error or answer that names the key has it replaced by [API key].
With PATENTREF_MCP_MODE=plan the server lists two tools in place of the 19. An agent looks up the operations it needs with search_api, then sends the requests with run_plan, several in one call:
-
search_api: Search the PatentRef OpenAPI spec and get compact matches (method, path, summary, typed parameters, response shape) to use with run_plan. query: words plus path:, tag:, method:<GET|POST|any> (default GET); an empty query lists the tags. An answer stops at 30,000 characters. Reads a cached copy, renewed daily; needs no API key.
-
run_plan: Run up to 20 GET requests to PatentRef paths under /api/v1/ found with search_api, in order; each step returns its status, items cut to fields, the next cursor or the API's error. Needs PATENTREF_API_KEY; each HTTP request, pages included, counts against the key's limits; a 403 or 429 stops the plan, as do 40,000 characters of answer and 120 seconds. Calls only the API's host; runs no code.
A search_api query is words plus, as needed, path: (part of a path, or a glob such as /api/v1/rules/*), tag: (such as structure or rules) and method: (GET by default, POST or any). Each match gives the method, the path, the summary, each parameter with where it goes, its type and whether it is required, and a short shape of the JSON the API answers. The whole spec never goes to the agent.
A run_plan step is an object; run_plan's input schema gives its shape:
{"steps": [
{"path": "/api/v1/structure/units/10034028/", "params": {"types": "Component"}, "fields": ["patent_id", "units.part", "units.locator"]},
{"path": "/api/v1/patent/", "params": {"q": {"_gte": {"patent_date": "2024-01-01"}}, "s": [{"patent_id": "asc"}], "o": {"size": 50}},
"pages": 3, "max_items": 120}
]}path is a path search_api gave, with its {names} filled in. params are the query values; an object or a list (q, f, s, o) is sent as JSON. A list answer (one that says count, total_hits or next_after, such as a search) comes back as its rows (items), the rest of the answer (answer) and the cursor of the next page (next); any other answer, such as a status record, comes back whole as answer. fields keeps only those fields of each row, or of a single record (a dotted name such as locator.start or units.part reaches into nested values). pages (1 to 5) follows the next page of a list through next_after where the API gives it, or through the values of the s sort fields of the last row; end a paged s with a unique field such as patent_id, since rows that share the last row's sort values can be passed over otherwise, and keep the s fields among the fields the API returns. max_items (1 to 1000) caps the rows of the step. When rows are cut, by max_items or by the size cap, items_cut says how many, and next resumes right after the last row returned when the step pages by the s sort; a list paged by next_after resumes after the page that row came on, which passes over the rest of that page (set o.size for smaller pages). Each step also says its status and the number of requests it took, or gives the API's error as its problem details.
What run_plan will and will not do:
- It sends GET only, to paths under
/api/v1/of the API (PATENTREF_BASE, by default https://patentref.io), never to another host. A path is a path: a URL, a host, a query string or a dot segment is refused before any request. - It follows a redirect only to the same scheme, host and port, and only to a path under
/api/v1/that meets the rules of a step's path, up to 3 times per request. - It sends your key in the
X-Api-Keyheader, never in a URL. A step that holds the key anywhere (its path, a parameter name or value,fields) is refused before any request, and the key is replaced by[API key]in any answer or error that names it. - At most 20 steps and 5 pages per step; at most 5,000,000 bytes read from one answer; the plan stops after 120 seconds, and when its answer reaches 40,000 characters (the rows, then the record or the error, of the step that reached it are cut, and the steps after it are skipped).
- An error from the API comes back in its step as its problem details; one over 2,000 characters keeps its main fields (
status,code,title,detail,type,instance,retry_after), each cut to 300 characters. - A 403 or 429 stops the plan; the steps after it are skipped. Other errors come back in their step and the plan goes on. Nothing is retried.
- It runs no code it is given.
search_api reads a copy of https://patentref.io/openapi.json (no key needed) that it keeps in your user cache folder and renews after a day, with the ETag when the server sends one. If neither the cache nor the API can be read, it uses the copy of the spec bundled in the package (API version 1.26.0). A spec over 8,000,000 bytes is not read. A cache file it cannot read, or one with a damaged fetch time (NaN, 1e300, a whole number of hundreds of digits, a text), ETag or Last-Modified, is fetched again. An answer of search_api stops at 30,000 characters, counted as the text an MCP client gets: the matches at the bottom are dropped before the others, then the parameters of the last match left (params_cut says how many), and cut says that the answer was cut.
What an MCP host sends a model for the tool list and the instructions, measured with tiktoken 0.14.0 on 2026-12-01 (0.5.0 and 0.6.0 on 2026-11-28):
| cl100k_base | o200k_base | |
|---|---|---|
| 0.5.0, 19 tools: tools/list | 7,129 | 7,254 |
| 0.5.0: instructions | 423 | 422 |
| 0.6.0 and 0.6.1, 19 tools: tools/list | 4,756 | 4,888 |
| 0.6.0 and 0.6.1: instructions | 199 | 198 |
| 0.6.0 plan mode: tools/list | 412 | 428 |
| 0.6.1 plan mode: tools/list | 436 | 452 |
| 0.6.0 and 0.6.1 plan mode: instructions | 187 | 186 |
| 0.6.1 plan mode: the two tools' names, descriptions and input schemas | 344 | 353 |
Per session (tools/list plus instructions, cl100k_base), 0.6.1 costs 4,955 tokens in the default mode and 623 in plan mode (5,086 and 638 in o200k_base); 0.6.0's plan mode cost 599, and 0.5.0 cost 7,552.
Method: start the server over stdio with no key, as an MCP client does (MCP Python SDK 1.30.0), initialize, list the tools; dump each tool with model_dump(mode="json", exclude_none=True); count json.dumps({"tools": [...]}, separators=(",", ":"), ensure_ascii=False) and the instructions string with len(tiktoken.get_encoding(name).encode(text)). Other models count tokens with other tokenizers, so read the numbers as a comparison.
Some agents call an API by writing code against its OpenAPI spec instead of calling one tool per endpoint. PatentRef's spec is at https://patentref.io/openapi.json (OpenAPI 3.1, no key needed to read it); the API takes the key in the X-Api-Key header.
Cloudflare's Code Mode SDK (the npm package @cloudflare/codemode, part of Cloudflare's Agents SDK) builds a two-tool MCP server, search and execute, from an OpenAPI document with openApiMcpServer from @cloudflare/codemode/mcp. It runs in a Cloudflare Worker with a Worker Loader binding (LOADER) and a DynamicWorkerExecutor; Cloudflare's guide has the whole Worker: https://developers.cloudflare.com/agents/model-context-protocol/guides/build-codemode-openapi-mcp-server/. For PatentRef, load the spec from https://patentref.io/openapi.json and let the request callback send only GET requests under /api/v1/ to https://patentref.io, with your key from a Worker secret. openApiMcpServer has no approval step of its own, so the callback is where requests are checked:
request: async ({ method, path, query }) => {
if (method !== "GET" || !path.startsWith("/api/v1/")) throw new Error("PatentRef: GET under /api/v1/ only");
const url = new URL(path, "https://patentref.io");
for (const [k, v] of Object.entries(query ?? {})) url.searchParams.set(k, typeof v === "string" ? v : JSON.stringify(v));
const res = await fetch(url, { headers: { "X-Api-Key": env.PATENTREF_API_KEY }, redirect: "manual" });
return res.json();
}Inside an agent's own Code Mode runtime, the same SDK's OpenApiConnector reads an OpenAPI document and makes each request through a request() method you write: https://developers.cloudflare.com/agents/tools/codemode/openapi/
goose (https://goose-docs.ai), the open source agent Block started, now a project of the AAIF at the Linux Foundation, works with MCP extensions; its docs on extensions and on Code Mode do not describe reading an OpenAPI document. Point it at the spec through plan mode: add patentref-mcp as a command-line extension with PATENTREF_MCP_MODE=plan, and search_api reads https://patentref.io/openapi.json for it. In ~/.config/goose/config.yaml:
extensions:
patentref:
name: PatentRef
cmd: patentref-mcp
args: []
enabled: true
envs: { "PATENTREF_API_KEY": "<your key>", "PATENTREF_MCP_MODE": "plan" }
type: stdio
timeout: 300goose configure does the same (Add Extension, then Command-line Extension, with the command patentref-mcp and the two environment variables). With goose's Code Mode extension turned on (Code Mode under Extensions in the desktop app, code_execution in goose configure), the JavaScript goose writes can call search_api and run_plan too.
See CHANGELOG.md in the repository: https://github.com/patentref/patentref-mcp/blob/main/CHANGELOG.md
MIT, see LICENSE. The data the API returns has its own license and attribution lines: https://patentref.io/LICENSES.md
Source: https://github.com/patentref/patentref-mcp. The package is published on PyPI (https://pypi.org/project/patentref-mcp/). Questions and problems: hello@patentref.io.