Skip to content

Conversation

@sirily11
Copy link
Contributor

@sirily11 sirily11 commented Jun 27, 2025

… transport configuration in mcp.ts

Summary by CodeRabbit

  • Chores
    • Updated internal dependencies to improve compatibility and performance.
    • Improved API client connection by enhancing transport configuration.
    • Updated environment settings for streaming service endpoint in testing workflows.

@vercel
Copy link

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rxchat-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 6:30am

@coderabbitai
Copy link

coderabbitai bot commented Jun 27, 2025

Walkthrough

The implementation of the createMCPClient function was refactored to use the StreamableHTTPClientTransport class for transport configuration, encapsulating connection details and removing explicit SSE and header setup. The environment variable URL used in testing was updated. Additionally, the @modelcontextprotocol/sdk dependency was added to the project's package.json.

Changes

File(s) Change Summary
lib/ai/mcp.ts Refactored createMCPClient to use StreamableHTTPClientTransport for transport setup.
package.json Added @modelcontextprotocol/sdk dependency.
.github/workflows/test.yml Updated MCP_ROUTER_SERVER_URL environment variable URL from /sse to /stream in e2e job.

Poem

In code’s green field, a stream now flows,
Wrapped in transport, neat and close.
With SDK fresh upon the vine,
Our client’s journey is by design.
Package lists and rivers run—
Refactored paths, a job well done!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 167ac2d and 739fba9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • .github/workflows/test.yml (1 hunks)
  • lib/ai/mcp.ts (1 hunks)
  • package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/test.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • package.json
  • lib/ai/mcp.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: e2e (22.x, 1, 3)
  • GitHub Check: e2e (22.x, 2, 3)
  • GitHub Check: e2e (22.x, 3, 3)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8465d7d and 167ac2d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • lib/ai/mcp.ts (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*.{ts,tsx}`: Use TypeScript for all code.

**/*.{ts,tsx}: Use TypeScript for all code.

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • lib/ai/mcp.ts
`lib/**/*.{ts,tsx}`: Each file should limit its size within 600 lines of code. If exceeded, split into multiple files and group using a folder.

lib/**/*.{ts,tsx}: Each file should limit its size within 600 lines of code. If exceeded, split into multiple files and group using a folder.

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • lib/ai/mcp.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: e2e (22.x, 3, 3)
  • GitHub Check: e2e (22.x, 2, 3)
  • GitHub Check: e2e (22.x, 1, 3)
🔇 Additional comments (3)
package.json (1)

47-47: Verify the SDK version is current and secure.

The dependency addition looks correct. Please ensure this is the latest stable version and check for any known security vulnerabilities.

What is the latest version of @modelcontextprotocol/sdk npm package and are there any known security vulnerabilities in version 1.13.2?
lib/ai/mcp.ts (2)

3-3: LGTM: Clean import statement.

The import follows TypeScript best practices and correctly imports from the new SDK.


12-15: Verify transport options parameter usage.

Ensure that the StreamableHTTPClientTransport constructor correctly accepts the options parameter for headers configuration as suggested in the security fix above.

#!/bin/bash
# Description: Check the StreamableHTTPClientTransport constructor signature and options

# Search for the StreamableHTTPClientTransport class definition to understand its constructor
ast-grep --pattern $'class StreamableHTTPClientTransport {
  $$$
  constructor($_, $_) {
    $$$
  }
  $$$
}'

# Also search for type definitions or interfaces related to transport options
rg -A 10 "StreamableHTTPClientTransport" --type ts

Comment on lines +7 to +10
const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);
// add x-api-key to the url
// biome-ignore lint/style/noNonNullAssertion: <explanation>
url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security concern: API key exposed in URL query parameters.

Adding the API key as a URL query parameter poses security risks as query parameters can be logged in server logs, browser history, and proxy logs. Consider using headers or request body instead.

-  const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);
-  // add x-api-key to the url
-  // biome-ignore lint/style/noNonNullAssertion: <explanation>
-  url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!);
+  const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);

Then pass the API key via headers in the transport options:

-  const transport = new StreamableHTTPClientTransport(url, {});
+  const transport = new StreamableHTTPClientTransport(url, {
+    headers: {
+      'x-api-key': process.env.MCP_ROUTER_SERVER_API_KEY!
+    }
+  });
🤖 Prompt for AI Agents
In lib/ai/mcp.ts around lines 7 to 10, the API key is currently added as a URL
query parameter, which exposes it to logs and browser history. To fix this,
remove the API key from the URL query parameters and instead include it in the
request headers when making the HTTP call. Update the code to set the
'x-api-key' header in the transport or fetch options rather than appending it to
the URL.

Comment on lines +5 to +16
export const createMCPClient = () => {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);
// add x-api-key to the url
// biome-ignore lint/style/noNonNullAssertion: <explanation>
url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!);

const transport = new StreamableHTTPClientTransport(url, {});
return createMCPClientSDK({
transport,
});
};
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling and environment variable validation.

The function uses non-null assertions without validating required environment variables, which could lead to runtime errors.

 export const createMCPClient = () => {
+  const serverUrl = process.env.MCP_ROUTER_SERVER_URL;
+  const apiKey = process.env.MCP_ROUTER_SERVER_API_KEY;
+  
+  if (!serverUrl) {
+    throw new Error('MCP_ROUTER_SERVER_URL environment variable is required');
+  }
+  
+  if (!apiKey) {
+    throw new Error('MCP_ROUTER_SERVER_API_KEY environment variable is required');
+  }
+  
+  let url: URL;
+  try {
+    url = new URL(serverUrl);
+  } catch (error) {
+    throw new Error(`Invalid MCP_ROUTER_SERVER_URL: ${error.message}`);
+  }
+
-  // biome-ignore lint/style/noNonNullAssertion: <explanation>
-  const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);
-  // add x-api-key to the url
-  // biome-ignore lint/style/noNonNullAssertion: <explanation>
-  url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!);

-  const transport = new StreamableHTTPClientTransport(url, {});
+  const transport = new StreamableHTTPClientTransport(url, {
+    headers: {
+      'x-api-key': apiKey
+    }
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const createMCPClient = () => {
// biome-ignore lint/style/noNonNullAssertion: <explanation>
const url = new URL(process.env.MCP_ROUTER_SERVER_URL!);
// add x-api-key to the url
// biome-ignore lint/style/noNonNullAssertion: <explanation>
url.searchParams.set('x-api-key', process.env.MCP_ROUTER_SERVER_API_KEY!);
const transport = new StreamableHTTPClientTransport(url, {});
return createMCPClientSDK({
transport,
});
};
export const createMCPClient = () => {
const serverUrl = process.env.MCP_ROUTER_SERVER_URL;
const apiKey = process.env.MCP_ROUTER_SERVER_API_KEY;
if (!serverUrl) {
throw new Error('MCP_ROUTER_SERVER_URL environment variable is required');
}
if (!apiKey) {
throw new Error('MCP_ROUTER_SERVER_API_KEY environment variable is required');
}
let url: URL;
try {
url = new URL(serverUrl);
} catch (error) {
throw new Error(`Invalid MCP_ROUTER_SERVER_URL: ${error.message}`);
}
const transport = new StreamableHTTPClientTransport(url, {
headers: {
'x-api-key': apiKey
}
});
return createMCPClientSDK({
transport,
});
};
🤖 Prompt for AI Agents
In lib/ai/mcp.ts around lines 5 to 16, the function createMCPClient uses
non-null assertions on environment variables without validation, risking runtime
errors. Add checks to verify that MCP_ROUTER_SERVER_URL and
MCP_ROUTER_SERVER_API_KEY are defined before using them. If either is missing,
throw a clear error to prevent proceeding with invalid configuration. This
ensures safer and more predictable behavior.

@codecov
Copy link

codecov bot commented Jun 27, 2025

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/ai/mcp.ts 20.00% 4 Missing ⚠️
Files with missing lines Coverage Δ
lib/ai/mcp.ts 20.00% <20.00%> (-30.00%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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