Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mcp #478

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Mcp #478

wants to merge 8 commits into from

Conversation

suhail-ak-s
Copy link

Add Model Context Protocol (MCP) Integration

Description

This PR adds support for the Model Context Protocol (MCP), enabling seamless integration with external AI capabilities, tools, and resources through a standardized protocol. The implementation includes both HTTP and STDIO communication modes, making it flexible for different deployment scenarios.

Key Features

  • New MCPNode for handling MCP communications
  • Support for both HTTP and STDIO communication modes
  • Dynamic tool discovery from MCP servers
  • Configurable server endpoints and headers
  • Browser-compatible implementation with appropriate polyfills
  • Proper error handling and type safety

Implementation Details

  • Added MCPNode class with full TypeScript type safety
  • Implemented browser polyfills for Node.js specific modules
  • Added configuration support through mcp-config.json
  • Integrated with existing native API infrastructure
  • Added proper error handling with specific error types
  • Support for dynamic tool discovery and metadata handling

Technical Considerations

  • Browser compatibility maintained through polyfills
  • Proper TypeScript types throughout the implementation
  • Error handling follows existing patterns
  • Configuration follows project conventions
  • No breaking changes to existing functionality

Testing

The implementation includes:

  • Type safety checks
  • Error handling for various scenarios
  • Browser environment compatibility
  • Support for both communication modes

Documentation

  • Added inline documentation for the MCP node
  • Included type definitions for all new interfaces
  • Added helper messages in the UI for configuration

Breaking Changes

None. This is a purely additive change that maintains compatibility with existing functionality.

Future Considerations

  • Additional tool discovery mechanisms
  • Enhanced error reporting
  • Extended configuration options
  • Performance optimizations for large-scale deployments

Copy link
Collaborator

@abrenneke abrenneke left a comment

Choose a reason for hiding this comment

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

Here's a first pass review!

package.json Outdated
@@ -55,7 +55,8 @@
},
"dependencies": {
"@ironclad/rivet-core": "workspace:^",
"@ironclad/rivet-node": "workspace:^"
"@ironclad/rivet-node": "workspace:^",
"@modelcontextprotocol/sdk": "^1.5.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should add this to the individual packages, not the root package.json

Copy link
Author

Choose a reason for hiding this comment

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

removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we have a better node body? Maybe it's just the example, but a blank body doesn't seem very helpful?

Copy link
Author

Choose a reason for hiding this comment

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

updated

alias: {
'@ironclad/rivet-core': resolve('../core/src/index.ts'),
'@ironclad/trivet': resolve('../trivet/src/index.ts'),
// 'node:child_process': resolve('./src/mocks/node-polyfills.ts'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we don't need these any more?

Copy link
Author

Choose a reason for hiding this comment

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

yes this is removed

@@ -0,0 +1,116 @@
// Mock implementation for node:child_process
export const spawn = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we don't need this file any more?

Copy link
Author

Choose a reason for hiding this comment

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

removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

it came back

@@ -34,6 +52,10 @@ export default defineConfig({
plugins: [visualizer()],
},
},
// define: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

Copy link
Author

Choose a reason for hiding this comment

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

removed

label: 'Configuration',
dataKey: 'config',
useInputToggleDataKey: 'useEndpointInput',
helperMessage: 'Configuration for the MCP server' });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please run prettier on this file?

Copy link
Author

Choose a reason for hiding this comment

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

prettier is done

@@ -0,0 +1,235 @@
# MCP Node for Rivet
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you move these docs into the docs project? And structure it like the existing per-node documentation?

Copy link
Author

Choose a reason for hiding this comment

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

moved

ignores = [],
} = options;

const resolvedPath = await resolveBaseDir(baseDir, path);
console.log('Reading directory from path:', resolvedPath);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to remove this and other console logs in the file

Copy link
Author

Choose a reason for hiding this comment

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

removed console.log

): Promise<{ output: string; metadata: Record<string, unknown> }> {
let configFile: object;
try {
configFile = this.data.useEndpointInput
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be behind a different data flag, not useEndpointInput

Copy link
Author

Choose a reason for hiding this comment

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

yes changed...

throw new MCPError(MCPErrorType.INVALID_RESPONSE, 'Invalid format for MCP configuration');
}

const serverId = this.data.useEndpointInput
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use getInputOrData for this pattern, getInputOrData(this.data, inputs, 'serverId')

@arbaaz
Copy link

arbaaz commented Feb 27, 2025

This looks great!

Quick question:

Will this work in node integration using runGraphInFile?

@@ -0,0 +1,116 @@
// Mock implementation for node:child_process
export const spawn = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it came back

alias: {
'@ironclad/rivet-core': resolve('../core/src/index.ts'),
'@ironclad/trivet': resolve('../trivet/src/index.ts'),
'node:child_process': resolve('./src/mocks/node-polyfills.ts'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why were these added back in?

@@ -48,6 +48,8 @@
"@google-cloud/vertexai": "^0.1.3",
"@google/generative-ai": "^0.21.0",
"@huggingface/inference": "^2.6.4",
"@modelcontextprotocol/sdk": "^1.5.0",
"@tauri-apps/api": "^1.5.3",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Core cannot depend on tauri

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.

5 participants