-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreator_kit_mcp.py
More file actions
executable file
·120 lines (101 loc) · 3.49 KB
/
Copy pathcreator_kit_mcp.py
File metadata and controls
executable file
·120 lines (101 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
"""Creator-kit stdio MCP server."""
from __future__ import annotations
import json
import sys
from typing import Any
from creator_kit_cli import asset_checklist, content_plan, project_brief
PROTOCOL_VERSION = "2024-11-05"
TOOLS = {
"creator_kit_project_brief": {
"description": "Return Creator-kit identity, surfaces, and workflow summary.",
"handler": lambda _args: project_brief(),
"inputSchema": {"type": "object", "properties": {}},
},
"create_content_plan": {
"description": "Create a reusable content plan from topic, audience, and channel.",
"handler": content_plan,
"inputSchema": {
"type": "object",
"properties": {
"topic": {"type": "string"},
"audience": {"type": "string"},
"channel": {"type": "string"},
},
"required": ["topic"],
},
},
"asset_readiness_checklist": {
"description": "Return a creator asset readiness checklist.",
"handler": asset_checklist,
"inputSchema": {
"type": "object",
"properties": {"asset_type": {"type": "string"}},
},
},
}
def handle_tool_call(
name: str, arguments: dict[str, Any] | None = None
) -> dict[str, Any]:
if name not in TOOLS:
raise ValueError(f"Unknown tool: {name}")
return TOOLS[name]["handler"](arguments or {})
def _tool_list() -> list[dict[str, Any]]:
return [
{
"name": name,
"description": spec["description"],
"inputSchema": spec["inputSchema"],
}
for name, spec in TOOLS.items()
]
def _response(message_id: Any, result: dict[str, Any]) -> dict[str, Any]:
return {"jsonrpc": "2.0", "id": message_id, "result": result}
def _error(message_id: Any, code: int, message: str) -> dict[str, Any]:
return {
"jsonrpc": "2.0",
"id": message_id,
"error": {"code": code, "message": message},
}
def handle_message(message: dict[str, Any]) -> dict[str, Any] | None:
method = message.get("method")
message_id = message.get("id")
params = message.get("params") or {}
if message_id is None:
return None
if method == "initialize":
return _response(
message_id,
{
"protocolVersion": PROTOCOL_VERSION,
"capabilities": {"tools": {}},
"serverInfo": {"name": "creator-kit", "version": "0.1.0"},
},
)
if method == "tools/list":
return _response(message_id, {"tools": _tool_list()})
if method == "tools/call":
try:
result = handle_tool_call(
params.get("name", ""), params.get("arguments") or {}
)
return _response(
message_id,
{"content": [{"type": "text", "text": json.dumps(result, indent=2)}]},
)
except ValueError as exc:
return _error(message_id, -32602, str(exc))
return _error(message_id, -32601, f"Unsupported method: {method}")
def main() -> None:
for line in sys.stdin:
if not line.strip():
continue
try:
reply = handle_message(json.loads(line))
except json.JSONDecodeError as exc:
reply = _error(None, -32700, f"Invalid JSON: {exc}")
if reply is not None:
sys.stdout.write(json.dumps(reply) + "\n")
sys.stdout.flush()
if __name__ == "__main__":
main()