Conversation
…d 16k for thinking models (play around with this param, it heavily determines output)
Add chat interrupts, auto scroll
There was a problem hiding this comment.
Pull request overview
This PR introduces a full MCP (Model Context Protocol) integration across the stack, adding OAuth-based MCP server auth, richer streaming chat UX (thinking/tool parts, interrupts, queues), and expanded message/harness schemas to persist the new metadata.
Changes:
- Adds MCP server configuration (URL + auth type) and an OAuth flow (FastAPI routes + Convex token storage).
- Refactors MCP client/tooling to support sessions, SSE responses, tool name sanitization, and parallel tool execution.
- Upgrades chat streaming end-to-end: reasoning parts, tool call visualization, interrupts/queueing, and usage capture/backfill.
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/fastapi/app/services/openrouter.py | Adds usage-inclusive streaming options, thinking support, and improved error/log handling for OpenRouter streams. |
| packages/fastapi/app/services/mcp_oauth.py | Implements OAuth discovery, PKCE, code exchange/refresh, and Convex token persistence helpers. |
| packages/fastapi/app/services/mcp_client.py | Major MCP client refactor: session caching, SSE-safe requests, parallel tool listing/calls, OAuth header resolution. |
| packages/fastapi/app/services/convex.py | Extends message save payload and adds usage backfill mutation helper. |
| packages/fastapi/app/routes/mcp_oauth.py | Adds OAuth start/callback/status/revoke endpoints for MCP servers. |
| packages/fastapi/app/routes/chat.py | Adds thinking/tool parts streaming, tool parallelism, interrupt draining for usage, and expanded persistence payload. |
| packages/fastapi/app/models.py | Introduces McpServer model and updates harness config to mcp_servers. |
| packages/fastapi/app/main.py | Registers new OAuth router and updates CORS allowlist. |
| packages/fastapi/app/config.py | Adds model mappings (incl. thinking variants) and OAuth-related settings. |
| packages/convex-backend/convex/userSettings.ts | Adds displayMode setting with validation/defaulting. |
| packages/convex-backend/convex/seed.ts | Updates seed harnesses to new mcpServers shape. |
| packages/convex-backend/convex/schema.ts | Adds MCP servers to harness schema, expands message schema (parts/toolCalls/usage/interrupted), adds mcpOAuthTokens table. |
| packages/convex-backend/convex/migrations.ts | Adds a harness migration helper for the new mcpServers field. |
| packages/convex-backend/convex/messages.ts | Adds message removal, interrupted message saving, assistant message enrichment, and usage backfill mutation. |
| packages/convex-backend/convex/mcpOAuthTokens.ts | Adds token storage/query/revoke endpoints for MCP OAuth tokens. |
| packages/convex-backend/convex/harnesses.ts | Updates harness create/update mutations for mcpServers. |
| packages/convex-backend/convex/conversations.ts | Limits conversation list query to 50 entries. |
| packages/convex-backend/convex/_generated/api.d.ts | Regenerates API typing for new Convex modules. |
| apps/web/vite.config.ts | Adds allowedHosts entry for an ngrok host. |
| apps/web/src/routes/onboarding.tsx | Replaces MCP selection with MCP server entry management (name/url/auth). |
| apps/web/src/routes/harnesses/index.tsx | Adds navigation to a dedicated harness edit route and updates MCP count display. |
| apps/web/src/routes/harnesses/$harnessId.tsx | New harness editor route with MCP server editing and OAuth connect/status UI. |
| apps/web/src/routes/chat/index.tsx | Adds message queueing, interrupts, thinking/tool part rendering, display modes, regenerate, and usage/model UI plumbing. |
| apps/web/src/routeTree.gen.ts | Route tree regeneration to include /harnesses/$harnessId. |
| apps/web/src/lib/use-chat-stream.ts | Extends stream protocol to include thinking events + usage/model on done; adds abort callback. |
| apps/web/src/lib/models.ts | Centralizes model options for the frontend. |
| apps/web/src/components/message-actions.tsx | Adds per-message actions (copy/regenerate/dev info) gated by display mode. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| return f"""<!DOCTYPE html> | ||
| <html> | ||
| <head><title>MCP OAuth</title></head> | ||
| <body> | ||
| <p>{"Connected successfully!" if success else f"Error: {error}"}</p> | ||
| <p>You can close this window.</p> | ||
| <script> | ||
| if (window.opener) {{ | ||
| window.opener.postMessage({json.dumps(message_data)}, "*"); | ||
| }} |
There was a problem hiding this comment.
The OAuth callback HTML both (1) interpolates error directly into the HTML (potential XSS if the error ever contains attacker-controlled text) and (2) posts a message to the opener with targetOrigin="*". Please HTML-escape any user-visible strings and restrict postMessage to a known origin (e.g. settings.frontend_url) so other origins can’t spoof the callback.
| const handler = (event: MessageEvent) => { | ||
| if (event.data?.type === "mcp-oauth-callback") { | ||
| window.removeEventListener("message", handler); | ||
| if (event.data.success) { | ||
| setStatus("connected"); | ||
| toast.success("Connected to MCP server via OAuth"); | ||
| } else { | ||
| toast.error(event.data.error || "OAuth connection failed"); | ||
| } | ||
| setConnecting(false); | ||
| popup?.close(); | ||
| } | ||
| }; | ||
| window.addEventListener("message", handler); |
There was a problem hiding this comment.
The message event handler accepts any postMessage payload with { type: "mcp-oauth-callback" } without validating event.origin or event.source (the popup). This allows any site to spoof a successful OAuth callback in the parent window. Please verify the origin matches your FastAPI base URL and that event.source === popup (and consider including/verifying a nonce/state).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…Harness into feat/mcp-implementation
|
⏺ --- Summary
Test plan
|
cole-ramer
left a comment
There was a problem hiding this comment.
The changes look good. The only main issue I found was the commenting/documentation. You do a good job with inline in function comments, but the more overview comments are lacking from almost every function. I think it would be better if going forward we all wrote quick little comments at the top of each function saying what it does and what it returns, and parameters if they aren't obvious. In general, we should as a group think about what documentation we are going to do, but I feel like the function comments are the bare minimum.
Fun fact, the PR description for this was generated by Harness itself, I'm sure that says enough

Feat: Complete MCP Implementation with OAuth Support, Chat Queues & Interrupts
This PR implements a comprehensive Model Context Protocol (MCP) integration with advanced chat features and OAuth authentication support.
Key Features
MCP OAuth & Authentication
none,bearer, andoauthauthentication typesAdvanced Chat Experience
MCP Server Management
Enhanced UI/UX
Technical Implementation
Backend (FastAPI)
Frontend (React)
Database (Convex)
Data Flow Improvements
Message Processing
MCP Integration
Breaking Changes
mcps: string[]tomcpServers: McpServer[]New Dependencies
Usage Examples
Adding MCP Servers
OAuth Flow
Message Queuing
This implementation provides a production-ready MCP integration with enterprise-grade OAuth support and significantly enhanced chat experience. All features are backward compatible and include comprehensive error handling and user feedback.