Run a server by name with optional transport. Usage: server [transport] Example: server basic_tool sse
()
| 13 | |
| 14 | |
| 15 | def run_server(): |
| 16 | """Run a server by name with optional transport. |
| 17 | |
| 18 | Usage: server <server-name> [transport] |
| 19 | Example: server basic_tool sse |
| 20 | """ |
| 21 | if len(sys.argv) < 2: |
| 22 | print("Usage: server <server-name> [transport]") |
| 23 | print("Available servers: basic_tool, basic_resource, basic_prompt, tool_progress,") |
| 24 | print(" sampling, elicitation, completion, notifications,") |
| 25 | print(" mcpserver_quickstart, structured_output, images") |
| 26 | print("Available transports: stdio (default), sse, streamable-http") |
| 27 | sys.exit(1) |
| 28 | |
| 29 | server_name = sys.argv[1] |
| 30 | transport = sys.argv[2] if len(sys.argv) > 2 else "stdio" |
| 31 | |
| 32 | try: |
| 33 | module = importlib.import_module(f".{server_name}", package=__name__) |
| 34 | module.mcp.run(cast(Literal["stdio", "sse", "streamable-http"], transport)) |
| 35 | except ImportError: |
| 36 | print(f"Error: Server '{server_name}' not found") |
| 37 | sys.exit(1) |