fake_mcp_server.py 715 B

12345678910111213141516171819202122232425
  1. """Minimal stdio / streamable-HTTP MCP server for tests (no network beyond loopback)."""
  2. import os
  3. import sys
  4. from mcp.server.mcpserver import MCPServer
  5. mcp = MCPServer("fake")
  6. @mcp.tool()
  7. def echo(text: str) -> str:
  8. """Echo text back, prefixed with the FAKE_MCP_TAG env value."""
  9. return f"{os.environ.get('FAKE_MCP_TAG', '')}:{text}"
  10. @mcp.tool()
  11. def secret_tag() -> str:
  12. """Return whether the secret env arrived."""
  13. return "yes" if os.environ.get("FAKE_MCP_SECRET") == "s3cret" else "no"
  14. if __name__ == "__main__":
  15. if "--http" in sys.argv:
  16. mcp.run(transport="streamable-http", host="127.0.0.1", port=int(os.environ["FAKE_MCP_PORT"]))
  17. else:
  18. mcp.run(transport="stdio")