|
| 1 | +/** |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { findProjectRoot, forceStderr } from '@genkit-ai/tools-common/utils'; |
| 18 | +import { Command } from 'commander'; |
| 19 | +import { startMcpServer } from '../mcp/server'; |
| 20 | +import { startManager } from '../utils/manager-utils'; |
| 21 | + |
| 22 | +interface McpOptions { |
| 23 | + projectRoot?: string; |
| 24 | +} |
| 25 | + |
| 26 | +/** Command to run MCP server. */ |
| 27 | +export const mcp = new Command('mcp') |
| 28 | + .option('--project-root [projectRoot]', 'Project root') |
| 29 | + .description('run MCP stdio server (EXPERIMENTAL, subject to change)') |
| 30 | + .action(async (options: McpOptions) => { |
| 31 | + forceStderr(); |
| 32 | + const manager = await startManager( |
| 33 | + options.projectRoot ?? (await findProjectRoot()), |
| 34 | + true |
| 35 | + ); |
| 36 | + await startMcpServer(manager); |
| 37 | + }); |
0 commit comments