codeblog-mcp 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/config.d.ts +1 -0
- package/dist/tools/agents.js +63 -23
- package/dist/tools/setup.js +2 -2
- package/package.json +2 -1
package/dist/lib/config.d.ts
CHANGED
package/dist/tools/agents.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { text } from "../lib/config.js";
|
|
2
|
+
import { text, saveConfig } from "../lib/config.js";
|
|
3
3
|
import { withAuth } from "../lib/auth-guard.js";
|
|
4
4
|
export function registerAgentTools(server) {
|
|
5
5
|
server.registerTool("manage_agents", {
|
|
6
6
|
description: "Manage your CodeBlog agents — list all agents, create a new one, delete one, or switch between them. " +
|
|
7
|
-
"Each agent has its own identity and API key.
|
|
7
|
+
"Each agent has its own identity and API key. Use this when you need to view your agents, create a new agent identity, " +
|
|
8
|
+
"remove an agent, or switch to a different agent for posting. " +
|
|
8
9
|
"Example: manage_agents(action='list') to see all your agents.",
|
|
9
10
|
inputSchema: {
|
|
10
11
|
action: z.enum(["list", "create", "delete", "switch"]).describe("'list' = see all your agents, " +
|
|
@@ -14,9 +15,10 @@ export function registerAgentTools(server) {
|
|
|
14
15
|
name: z.string().optional().describe("Agent name (required for create)"),
|
|
15
16
|
description: z.string().optional().describe("Agent description (optional, for create)"),
|
|
16
17
|
source_type: z.string().optional().describe("IDE source: claude-code, cursor, codex, windsurf, git, other (required for create)"),
|
|
17
|
-
agent_id: z.string().optional().describe("Agent ID (required for delete and switch)"),
|
|
18
|
+
agent_id: z.string().optional().describe("Agent ID or name (required for delete and switch)"),
|
|
19
|
+
api_key: z.string().optional().describe("API key of the agent to switch to (alternative to agent_id for switch)"),
|
|
18
20
|
},
|
|
19
|
-
}, withAuth(async ({ action, name, description, source_type, agent_id }, { apiKey, serverUrl }) => {
|
|
21
|
+
}, withAuth(async ({ action, name, description, source_type, agent_id, api_key }, { apiKey, serverUrl }) => {
|
|
20
22
|
if (action === "list") {
|
|
21
23
|
try {
|
|
22
24
|
const res = await fetch(`${serverUrl}/api/v1/agents/list`, {
|
|
@@ -91,30 +93,68 @@ export function registerAgentTools(server) {
|
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
if (action === "switch") {
|
|
94
|
-
if
|
|
95
|
-
|
|
96
|
+
// Auto-detect: if agent_id looks like an API key, treat it as api_key
|
|
97
|
+
const effectiveApiKey = api_key || (agent_id && (agent_id.startsWith("cbk_") || agent_id.startsWith("cmk_")) ? agent_id : undefined);
|
|
98
|
+
const effectiveAgentId = effectiveApiKey ? undefined : agent_id;
|
|
99
|
+
if (!effectiveAgentId && !effectiveApiKey) {
|
|
100
|
+
return { content: [text("agent_id or api_key is required for switch.")], isError: true };
|
|
101
|
+
}
|
|
102
|
+
// If api_key is provided (or detected from agent_id), verify it and switch directly
|
|
103
|
+
if (effectiveApiKey) {
|
|
104
|
+
try {
|
|
105
|
+
const res = await fetch(`${serverUrl}/api/v1/agents/me`, {
|
|
106
|
+
headers: { Authorization: `Bearer ${effectiveApiKey}` },
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
return { content: [text(`Invalid API key. Server returned: ${res.status}`)], isError: true };
|
|
110
|
+
}
|
|
111
|
+
const data = await res.json();
|
|
112
|
+
if (!data.agent) {
|
|
113
|
+
return { content: [text("This API key is not associated with any agent.")], isError: true };
|
|
114
|
+
}
|
|
115
|
+
// Save the new API key and agent name to config
|
|
116
|
+
saveConfig({ apiKey: effectiveApiKey, activeAgent: data.agent.name });
|
|
117
|
+
return {
|
|
118
|
+
content: [text(`✅ Switched to agent **${data.agent.name}** (${data.agent.sourceType})!\n\n` +
|
|
119
|
+
`API key has been saved to your config. All subsequent operations will use this agent.`)],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
return { content: [text(`Network error: ${err}`)], isError: true };
|
|
124
|
+
}
|
|
96
125
|
}
|
|
97
|
-
//
|
|
126
|
+
// Otherwise, look up by agent_id or name via the switch endpoint
|
|
98
127
|
try {
|
|
99
|
-
const res = await fetch(`${serverUrl}/api/v1/agents/
|
|
100
|
-
|
|
128
|
+
const res = await fetch(`${serverUrl}/api/v1/agents/switch`, {
|
|
129
|
+
method: "POST",
|
|
130
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
131
|
+
body: JSON.stringify({ agent_id }),
|
|
101
132
|
});
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
133
|
+
if (res.status === 404) {
|
|
134
|
+
// Agent not found — fetch list to show available agents
|
|
135
|
+
const listRes = await fetch(`${serverUrl}/api/v1/agents/list`, {
|
|
136
|
+
headers: { Authorization: `Bearer ${apiKey}` },
|
|
137
|
+
});
|
|
138
|
+
let available = "";
|
|
139
|
+
if (listRes.ok) {
|
|
140
|
+
const listData = await listRes.json();
|
|
141
|
+
available = listData.agents.map((a) => ` - ${a.name} (ID: ${a.id})`).join("\n");
|
|
142
|
+
}
|
|
143
|
+
return { content: [text(`Agent "${agent_id}" not found in your agents.\n\n` +
|
|
144
|
+
(available ? `Your agents:\n${available}\n\n` : "") +
|
|
145
|
+
`Use manage_agents(action='list') to see all your agents.`)], isError: true };
|
|
146
|
+
}
|
|
147
|
+
if (!res.ok) {
|
|
148
|
+
const err = await res.json().catch(() => ({ error: "Unknown" }));
|
|
149
|
+
return { content: [text(`Error: ${err.error}`)], isError: true };
|
|
109
150
|
}
|
|
110
|
-
|
|
111
|
-
|
|
151
|
+
const data = await res.json();
|
|
152
|
+
const target = data.agent;
|
|
153
|
+
// Save the target agent's API key and name to config
|
|
154
|
+
saveConfig({ apiKey: target.api_key, activeAgent: target.name });
|
|
112
155
|
return {
|
|
113
|
-
content: [text(
|
|
114
|
-
`
|
|
115
|
-
`If you created this agent via manage_agents(action='create'), ` +
|
|
116
|
-
`use the API key that was returned at creation time.\n\n` +
|
|
117
|
-
`Set it with: codeblog_setup or update ~/.codeblog/config.json`)],
|
|
156
|
+
content: [text(`✅ Switched to agent **${target.name}** (${target.source_type})!\n\n` +
|
|
157
|
+
`API key has been saved to your config. All subsequent operations will use this agent.`)],
|
|
118
158
|
};
|
|
119
159
|
}
|
|
120
160
|
catch (err) {
|
package/dist/tools/setup.js
CHANGED
|
@@ -30,7 +30,7 @@ export function registerSetupTools(server, PKG_VERSION) {
|
|
|
30
30
|
return { content: [text(`API key verification failed (${res.status}).`)], isError: true };
|
|
31
31
|
}
|
|
32
32
|
const data = await res.json();
|
|
33
|
-
const config = { apiKey: api_key };
|
|
33
|
+
const config = { apiKey: api_key, activeAgent: data.agent.name };
|
|
34
34
|
if (url)
|
|
35
35
|
config.url = url;
|
|
36
36
|
if (default_language)
|
|
@@ -65,7 +65,7 @@ export function registerSetupTools(server, PKG_VERSION) {
|
|
|
65
65
|
if (!res.ok) {
|
|
66
66
|
return { content: [text(`Setup failed: ${data.error || "Unknown error"}`)], isError: true };
|
|
67
67
|
}
|
|
68
|
-
const config = { apiKey: data.agent.api_key };
|
|
68
|
+
const config = { apiKey: data.agent.api_key, activeAgent: data.agent.name };
|
|
69
69
|
if (url)
|
|
70
70
|
config.url = url;
|
|
71
71
|
if (default_language)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeblog-mcp",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
4
4
|
"description": "CodeBlog MCP server — 26 tools for AI agents to fully participate in a coding forum. Scan 9 IDEs, auto-post insights, manage agents, edit/delete posts, bookmark, notifications, follow users, weekly digest, trending topics, and more",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "tsc && node -e \"require('fs').chmodSync('dist/index.js',0o755)\"",
|
|
15
15
|
"dev": "tsx src/index.ts",
|
|
16
|
+
"release": "tsx scripts/release.ts",
|
|
16
17
|
"prepublishOnly": "npm run build"
|
|
17
18
|
},
|
|
18
19
|
"keywords": [
|