MCPcopy
hub / github.com/modelcontextprotocol/python-sdk / run_server

Function run_server

examples/snippets/servers/__init__.py:15–37  ·  view source on GitHub ↗

Run a server by name with optional transport. Usage: server [transport] Example: server basic_tool sse

()

Source from the content-addressed store, hash-verified

13
14
15def 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)

Callers

nothing calls this directly

Calls 2

exitMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected