Skip to content

Repository files navigation

UK Parliament MCP

A Code Mode Model Context Protocol server for every public API listed by the UK Parliament developer hub. It runs on Cloudflare Workers and gives MCP clients a compact way to discover and query the Parliament APIs.

Note

This is an independent project and is not affiliated with or endorsed by the UK Parliament.

Hosted server

The public MCP endpoint is:

https://uk-parliament-mcp.ghostwriternr.workers.dev/mcp

For clients that support .mcp.json:

{
  "mcpServers": {
    "uk-parliament": {
      "type": "http",
      "url": "https://uk-parliament-mcp.ghostwriternr.workers.dev/mcp"
    }
  }
}

The hosted endpoint is unauthenticated and intended for reasonable public use. For production or high-volume workloads, deploy your own instance and protect it with Cloudflare Access and rate limiting.

Deploy your own

Deploy to Cloudflare

The Deploy to Cloudflare flow creates a copy of this repository in your GitHub or GitLab account, provisions the R2 bucket declared in wrangler.jsonc, deploys the Worker, seeds its API catalog, and configures Workers Builds for subsequent pushes. No Parliament API credentials are required.

After deployment, use https://<your-worker>.<your-subdomain>.workers.dev/mcp as the URL in your MCP client. Consider adding Cloudflare Access and rate limiting before sharing the endpoint.

Tools

The server exposes two tools:

  • search runs JavaScript against a pre-resolved catalog of Parliament OpenAPI specifications. It has no network access. Use it to find operation paths, parameters, and response schemas.
  • execute runs JavaScript with a constructive parliament.request() capability. Use it to combine, filter, and transform responses from multiple Parliament APIs in one call.

Generated code runs in isolated Dynamic Workers. Ambient network access and importable environment bindings are disabled. Only the execute worker receives the narrowly scoped, GET-only Parliament gateway.

Results follow JSON serialization semantics: undefined object properties are omitted and undefined array entries become null.

Supported APIs

The catalog currently contains 160 operations across 12 API families:

API Version
Members v1
Register of Interests v2
Commons Votes v1
Lords Votes v1
Oral Questions and Motions v1
Statutory Instruments v2
Treaties v1
Erskine May v1
Parliament Now v1
Bills v1
Written Questions and Statements v1
Committees v1

Only the latest version advertised by each service is included.

Architecture

MCP client
    |
    v
Cloudflare Worker (/mcp)
    |-- search  -> isolated Dynamic Worker -> catalog from R2
    `-- execute -> isolated Dynamic Worker -> ParliamentGateway RPC
                                                |
                                                v
                                      fixed Parliament API origins

The host-side gateway owns URL validation, timeouts, response-size limits, decoding, and structured failures. Search and execute use separate Dynamic Worker loaders because they have different security policies and resource limits.

The normalized OpenAPI catalog is stored in R2 and refreshed daily at 03:00 UTC.

Development

Requirements:

  • Node.js 22 or newer
  • A Cloudflare account with Workers, R2, and Dynamic Worker loaders available
  • Wrangler authentication (npx wrangler login)

Install dependencies and run all checks:

npm ci
npm run types
npm run check

For local development, create the R2 bucket once and seed the catalog:

npx wrangler r2 bucket create uk-parliament-mcp-spec
npm run seed

Run locally:

npm run dev

The local MCP endpoint is http://localhost:8787/mcp.

Deployment

Wrangler deploys to the account selected by your current authentication, then seeds the newly provisioned R2 bucket:

npm run deploy

The repository does not include a Cloudflare account ID or credentials. If you change the Worker or bucket names, update wrangler.jsonc before seeding and deploying.

Security

Generated workers have explicit CPU and subrequest limits, no ambient network access, and no access to the host Worker's bindings. The execute worker can only make validated GET requests to the configured Parliament API origins.

The server itself does not authenticate MCP clients because the upstream APIs are public. A self-hosted production deployment should add Cloudflare Access or another authentication and rate-limiting policy in front of /mcp.

License

MIT

About

Code Mode MCP server for every public UK Parliament API, running on Cloudflare Workers

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages