Skip to content
This repository was archived by the owner on Jan 19, 2026. It is now read-only.

Commit 65beb5c

Browse files
authored
feat: Compatible with int type strings (#4)
1 parent ee63bad commit 65beb5c

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "coze-mcp-server"
3-
version = "0.0.3"
3+
version = "0.0.4"
44
description = "MCP Server for Coze(coze.com/coze.cn)"
55
authors = [
66
{ name = "chyroc", email = "chyroc@bytedance.com" },

src/coze_mcp_server/server.py

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ChatEventType,
1313
Voice,
1414
User,
15+
Workspace,
1516
)
1617
from mcp.server import FastMCP # type: ignore
1718
from pydantic import BaseModel # type: ignore
@@ -79,85 +80,110 @@ async def workflow_chat(self, bot_id: str, workflow_id: str, content: str) -> st
7980
server = CozeServer(conf.api_base, conf.api_token)
8081

8182

83+
def wrap_id(model: Union[BaseModel, List[BaseModel]], field: str = "id"):
84+
if isinstance(model, list):
85+
res = []
86+
for item in model:
87+
v = item.model_dump()
88+
v[field] = "id:" + v[field]
89+
res.append(v)
90+
return res
91+
92+
v = model.model_dump()
93+
v[field] = "id:" + v[field]
94+
return v
95+
96+
97+
def unwrap_id(value: str) -> str:
98+
if value and value.startswith("id:"):
99+
return str(value[3:])
100+
return str(value)
101+
102+
82103
@mcp.tool(description="get self user info")
83104
async def get_me() -> User:
84105
return await server.coze.users.me()
85106

86107

87108
@mcp.tool(description="list coze workspaces")
88-
async def list_workspaces():
109+
async def list_workspaces() -> List[Workspace]:
89110
res = await server.coze.workspaces.list()
90-
return [item async for item in res]
111+
items = [item async for item in res]
112+
return wrap_id(items) # type: ignore
91113

92114

93115
@mcp.tool(description="list bots in workspaces")
94-
async def list_bots(workspace_id: Union[int, str]):
95-
res = await server.coze.bots.list(space_id=str(workspace_id))
96-
return res.items
116+
async def list_bots(workspace_id: str) -> List[Bot]:
117+
res = await server.coze.bots.list(space_id=unwrap_id(workspace_id))
118+
items = [item async for item in res]
119+
return wrap_id(items, "bot_id") # type: ignore
97120

98121

99122
@mcp.tool(description="retrieve bot")
100-
async def retrieve_bot(bot_id: Union[int, str]) -> Bot:
101-
return await server.coze.bots.retrieve(bot_id=str(bot_id))
123+
async def retrieve_bot(bot_id: str) -> Bot:
124+
bot = await server.coze.bots.retrieve(bot_id=unwrap_id(bot_id))
125+
return wrap_id(bot, "bot_id") # type: ignore
102126

103127

104128
@mcp.tool(description="create bot in workspaces")
105129
async def create_bot(
106-
workspace_id: Union[int, str],
130+
workspace_id: str,
107131
name: str,
108132
description: Optional[str] = None,
109133
prompt: Optional[str] = None,
110134
) -> Bot:
111-
return await server.coze.bots.create(
112-
space_id=str(workspace_id),
135+
bot = await server.coze.bots.create(
136+
space_id=unwrap_id(workspace_id),
113137
name=name,
114138
description=description,
115139
prompt_info=None if not prompt else BotPromptInfo(prompt=prompt),
116140
)
141+
return wrap_id(bot, "bot_id") # type: ignore
117142

118143

119144
@mcp.tool(description="update bot info")
120145
async def update_bot(
121-
bot_id: Union[int, str],
146+
bot_id: str,
122147
name: Optional[str] = None,
123148
description: Optional[str] = None,
124149
prompt: Optional[str] = None,
125150
):
126151
await server.coze.bots.update(
127-
bot_id=str(bot_id),
152+
bot_id=unwrap_id(bot_id),
128153
name=name,
129154
description=description,
130155
prompt_info=None if not prompt else BotPromptInfo(prompt=prompt),
131156
)
132157

133158

134159
@mcp.tool(description="publish bot info")
135-
async def publish_bot(bot_id: Union[int, str]) -> Bot:
136-
return await server.coze.bots.publish(
137-
bot_id=str(bot_id),
160+
async def publish_bot(bot_id: str) -> Bot:
161+
bot = await server.coze.bots.publish(
162+
bot_id=unwrap_id(bot_id),
138163
)
164+
return wrap_id(bot, "bot_id") # type: ignore
139165

140166

141167
@mcp.tool(description="chat with bot")
142168
async def chat_with_bot(
143-
bot_id: Union[int, str],
169+
bot_id: str,
144170
content: str,
145171
) -> str:
146172
return await server.bot_chat(
147-
bot_id=str(bot_id),
173+
bot_id=unwrap_id(bot_id),
148174
content=content,
149175
)
150176

151177

152178
@mcp.tool(description="chat with bot")
153179
async def chat_with_workflow(
154-
bot_id: Union[int, str],
155-
workflow_id: Union[int, str],
180+
bot_id: str,
181+
workflow_id: str,
156182
content: str,
157183
) -> str:
158184
return await server.workflow_chat(
159-
bot_id=str(bot_id),
160-
workflow_id=str(workflow_id),
185+
bot_id=unwrap_id(bot_id),
186+
workflow_id=unwrap_id(workflow_id),
161187
content=content,
162188
)
163189

@@ -166,4 +192,4 @@ async def chat_with_workflow(
166192
async def list_voices() -> List[Voice]:
167193
res = await server.coze.audio.voices.list()
168194
items = [item async for item in res]
169-
return items
195+
return wrap_id(items, "voice_id") # type: ignore

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)