Skip to content

feat: add Web Search MCP server (stateless, /mcp, OAuth + API token)#383

Open
G4brym wants to merge 1 commit into
cloudflare:mainfrom
G4brym:add-websearch-mcp-server
Open

feat: add Web Search MCP server (stateless, /mcp, OAuth + API token)#383
G4brym wants to merge 1 commit into
cloudflare:mainfrom
G4brym:add-websearch-mcp-server

Conversation

@G4brym

@G4brym G4brym commented Jun 1, 2026

Copy link
Copy Markdown
Member

What

Adds a new Web Search MCP server (apps/websearch), deployed at websearch.mcp.cloudflare.com.

Design

  • Stateless — uses the agents SDK createMcpHandler (a fresh McpServer per request); no Durable Objects, no UserDetails, no session state.
  • /mcp only — streamable HTTP; no /sse.
  • No account tools — no accounts_list / set_active_account. The web_search tool takes an account_id parameter instead, so an agent can connect and search immediately.
  • Dual auth:
    • OAuth endpoints are registered (/authorize, /token, /register, .well-known/*) so tokenless clients get the OAuth flow.
    • If the request carries a raw Cloudflare API token as a Bearer token, OAuth is skipped and the token is used directly against the Web Search API. (OAuth-issued tokens are detected via isApiTokenRequest and still flow through the OAuth provider.)
  • web_search is gated behind the websearch.run OAuth scope; reads the access token via getMcpAuthContext().

Dependencies

  • agents bumped to 0.13.3 (for createMcpHandler / getMcpAuthContext), with @modelcontextprotocol/sdk@1.29.0 + zod@3.25.76 to match. Scoped to this app only — no other server's versions change.

Validation

  • pnpm -F websearch check:types
  • pnpm -F websearch check:lint
  • prettier --check
  • wrangler deploy --dry-run ✅ (bundles cleanly)

TODO before deploy

  • Metrics: this version uses a plain McpServer rather than CloudflareMCPServer, because the shared @repo/mcp-common is pinned to zod 3.24.2/SDK 1.20.2 and can't be bumped without changing the other servers. TODO(RAG-1300) to add stateless-server support to CloudflareMCPServer/metrics so this server can report tool-call metrics (and per-user userId via getMcpAuthContext).
  • Staging/prod OAUTH_KV ids are REPLACE_WITH_* placeholders pending infra.

@G4brym G4brym force-pushed the add-websearch-mcp-server branch from 8e63bcb to b08df33 Compare June 1, 2026 16:07
@G4brym G4brym changed the title feat: add Web Search MCP server feat: add Web Search MCP server (stateless, /mcp, OAuth + API token) Jun 1, 2026
@G4brym G4brym force-pushed the add-websearch-mcp-server branch 3 times, most recently from f41f54b to 5ed0d64 Compare June 1, 2026 16:24
Comment thread apps/websearch/README.md Outdated
"mcpServers": {
"cloudflare": {
"command": "npx",
"args": ["mcp-remote", "https://websearch.mcp.cloudflare.com/mcp"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls dont use mcp-remote now

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread apps/websearch/types.d.ts
Comment on lines +1 to +5
import type { TestEnv } from './vitest.config'

declare module 'cloudflare:test' {
interface ProvidedEnv extends TestEnv {}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might need to change with the upgrade to vitest 4

Comment thread apps/websearch/wrangler.jsonc Outdated
"kv_namespaces": [
{
"binding": "OAUTH_KV",
"id": "REPLACE_WITH_WEBSEARCH_PRODUCTION_OAUTH_KV_ID"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

.describe('Maximum number of results to return (up to 20).')

export function registerWebSearchTools(server: McpServer) {
server.tool(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use the same account logic as the other servers that would be awesome.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@G4brym G4brym force-pushed the add-websearch-mcp-server branch 8 times, most recently from 80e6dcf to 0962fde Compare June 2, 2026 15:46
@G4brym G4brym force-pushed the add-websearch-mcp-server branch from 0962fde to b77f7f2 Compare June 2, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants