Skip to content

Conversation

@jonathannorris
Copy link
Member

feat: Add API request headers for MCP server tracking

Solution

  • Added MCP-specific headers to all API requests made through the MCP server
  • Dynamically set the command field to the specific MCP tool name (e.g., "list_features", "create_project")
  • Fixed bug in setDVCReferrer where caller parameter was ignored

Changes

  • New: src/mcp/utils/headers.ts - Utilities for setting MCP headers
  • Updated: src/mcp/index.ts - Initialize headers on server startup
  • Updated: src/mcp/utils/api.ts - Set tool-specific command before each API call
  • Fixed: src/api/apiClient.ts - Use caller parameter instead of hardcoded 'cli'

Result

API requests now include proper identification:

  • CLI requests: {"command":"<cli_command>","caller":"cli","version":"<version>"}
  • MCP requests: {"command":"<mcp_tool>","caller":"mcp","version":"<version>"}

This enables better analytics, debugging, and tracking of MCP tool usage patterns.

@jonathannorris jonathannorris changed the title feat: Add API request headers for MCP server tracking feat(FDN-547): Add API request headers for MCP server tracking Jul 17, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

// Set the referrer to identify this as an MCP request
// Command will be set dynamically for each tool call
// Caller is 'mcp' to distinguish from 'cli' and other callers
setDVCReferrer('mcp', version, 'mcp')
Copy link
Member

Choose a reason for hiding this comment

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

mcp local?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not going to worry about that distinction until we figure out how we are going to deploy this.

*/
export function setMCPToolCommand(toolName: string): void {
// Update the command to be the tool name, keeping version and caller the same
setDVCReferrer(toolName, mcpVersion, 'mcp')
Copy link
Member

Choose a reason for hiding this comment

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

mcp local instead?

@jonathannorris jonathannorris requested a review from JamieSinn July 18, 2025 19:13
@jonathannorris jonathannorris merged commit 07cc338 into chore-mcp-planning-doc Jul 18, 2025
8 checks passed
@jonathannorris jonathannorris deleted the feat-mcp-api-headers branch July 18, 2025 19:43
jonathannorris added a commit that referenced this pull request Jul 23, 2025
* feat: add MCP API headers to requests

* feat: add headers.ts file
jonathannorris added a commit that referenced this pull request Jul 25, 2025
* feat: add MCP API headers to requests

* feat: add headers.ts file
jonathannorris added a commit that referenced this pull request Aug 11, 2025
* feat: add MCP API headers to requests

* feat: add headers.ts file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants