mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
92afdb1f2c
Provide native Intelligence SDK operations and runtime routes with application-owned identity, durable runs, A2UI, MCP Apps, entitlements, Inspector metadata, and telemetry. Include package docs, hosting examples, and regression tests.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import hashlib
|
|
import json
|
|
|
|
from copilotkit_runtime.mcp_apps import MCPAppsConfig, MCPAppsMiddleware, MCPServer
|
|
|
|
|
|
def test_server_hash_matches_browser_contract_without_credentials():
|
|
server = MCPServer(
|
|
url="http://localhost:8000/mcp", server_id="example", headers={"Authorization": "secret"}
|
|
)
|
|
expected = hashlib.md5(
|
|
json.dumps({"type": "http", "url": server.url}, separators=(",", ":")).encode()
|
|
).hexdigest()
|
|
assert server.server_hash == expected
|
|
|
|
|
|
async def test_proxy_allowlist_rejects_unknown_method_without_network():
|
|
middleware = MCPAppsMiddleware(
|
|
MCPAppsConfig(servers=(MCPServer(url="http://localhost:1/mcp", server_id="known"),))
|
|
)
|
|
events = [
|
|
event
|
|
async for event in middleware.proxy(
|
|
{"serverId": "known", "method": "admin/delete"}, "default"
|
|
)
|
|
]
|
|
assert events[-1]["type"] == "RUN_FINISHED"
|
|
assert "error" in events[-1]["result"]
|
|
|
|
|
|
async def test_proxy_does_not_cross_agent_scope():
|
|
middleware = MCPAppsMiddleware(
|
|
MCPAppsConfig(
|
|
servers=(
|
|
MCPServer(url="http://localhost:1/mcp", server_id="private", agent_id="other"),
|
|
)
|
|
)
|
|
)
|
|
events = [
|
|
event
|
|
async for event in middleware.proxy({"serverId": "private", "method": "ping"}, "default")
|
|
]
|
|
assert events[-1]["result"] == {"error": "Unknown MCP server"}
|