feat: Enhance MCP service configuration with stdio transport support
- Added support for stdio transport type in MCP service configuration, allowing command execution via standard input/output. - Updated MCPService interface to include optional stdio_config and env_vars fields for managing command arguments and environment variables. - Enhanced frontend components to handle stdio transport, including dynamic form fields for command and arguments. - Implemented validation logic for stdio configuration in the service update process, ensuring proper handling of required fields. - Updated backend logic to manage stdio transport connections and ensure proper client lifecycle management.
This commit is contained in:
@@ -73,6 +73,18 @@ func (t *MCPTool) Execute(ctx context.Context, args map[string]interface{}) (*ty
|
||||
}, nil
|
||||
}
|
||||
|
||||
// For stdio transport, ensure connection is released after use
|
||||
isStdio := t.service.TransportType == types.MCPTransportStdio
|
||||
if isStdio {
|
||||
defer func() {
|
||||
if err := client.Disconnect(); err != nil {
|
||||
logger.GetLogger(ctx).Warnf("Failed to disconnect stdio MCP client: %v", err)
|
||||
} else {
|
||||
logger.GetLogger(ctx).Infof("Stdio MCP client disconnected after tool execution")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Call the tool via MCP
|
||||
result, err := client.CallTool(ctx, t.mcpTool.Name, args)
|
||||
if err != nil {
|
||||
@@ -194,6 +206,16 @@ func RegisterMCPTools(ctx context.Context, registry *ToolRegistry, services []*t
|
||||
continue
|
||||
}
|
||||
|
||||
// For stdio transport, ensure connection is released after listing tools
|
||||
isStdio := service.TransportType == types.MCPTransportStdio
|
||||
if isStdio {
|
||||
defer func() {
|
||||
if err := client.Disconnect(); err != nil {
|
||||
logger.GetLogger(ctx).Warnf("Failed to disconnect stdio MCP client after listing tools: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// List tools from the service with timeout
|
||||
// Create a new context with timeout for this specific operation
|
||||
listCtx, cancel := context.WithTimeout(ctx, listToolsTimeout)
|
||||
|
||||
Reference in New Issue
Block a user