mcp-google-tasks 0.1.0
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/LICENSE +21 -0
- package/README.md +301 -0
- package/README.ru.md +301 -0
- package/dist/client.js +333 -0
- package/dist/config.js +83 -0
- package/dist/index.js +119 -0
- package/dist/telemetry.js +120 -0
- package/dist/tools/completion.js +48 -0
- package/dist/tools/raw.js +33 -0
- package/dist/tools/tasklists.js +83 -0
- package/dist/tools/tasks.js +184 -0
- package/dist/tools/util.js +74 -0
- package/dist/types.js +44 -0
- package/package.json +60 -0
- package/test/dist-smoke.test.js +175 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
6
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
7
|
+
|
|
8
|
+
import { GoogleTasksClient } from "../dist/client.js";
|
|
9
|
+
import { registerTaskListTools } from "../dist/tools/tasklists.js";
|
|
10
|
+
import { registerTaskTools } from "../dist/tools/tasks.js";
|
|
11
|
+
import { registerCompletionTools } from "../dist/tools/completion.js";
|
|
12
|
+
import { registerRawTool } from "../dist/tools/raw.js";
|
|
13
|
+
|
|
14
|
+
const ALL_TOOLS = [
|
|
15
|
+
"clear_completed_tasks",
|
|
16
|
+
"complete_task",
|
|
17
|
+
"create_task",
|
|
18
|
+
"create_tasklist",
|
|
19
|
+
"delete_task",
|
|
20
|
+
"delete_tasklist",
|
|
21
|
+
"get_task",
|
|
22
|
+
"get_tasklist",
|
|
23
|
+
"list_tasklists",
|
|
24
|
+
"list_tasks",
|
|
25
|
+
"move_task",
|
|
26
|
+
"raw_request",
|
|
27
|
+
"reopen_task",
|
|
28
|
+
"update_task",
|
|
29
|
+
"update_tasklist",
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
test("dist client rejects foreign-origin paths before sending the Bearer token", async () => {
|
|
33
|
+
const original = globalThis.fetch;
|
|
34
|
+
let called = false;
|
|
35
|
+
globalThis.fetch = async () => {
|
|
36
|
+
called = true;
|
|
37
|
+
return new Response("{}", { status: 200 });
|
|
38
|
+
};
|
|
39
|
+
try {
|
|
40
|
+
const client = new GoogleTasksClient({
|
|
41
|
+
accessToken: "SECRET",
|
|
42
|
+
apiBase: "https://tasks.googleapis.com",
|
|
43
|
+
timeoutMs: 1000,
|
|
44
|
+
maxRetries: 0,
|
|
45
|
+
});
|
|
46
|
+
await assert.rejects(() => client.request("GET", "https://example.invalid/steal"), /foreign origin/);
|
|
47
|
+
assert.equal(called, false);
|
|
48
|
+
} finally {
|
|
49
|
+
globalThis.fetch = original;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("dist client sends the Bearer token and JSON bodies", async () => {
|
|
54
|
+
const original = globalThis.fetch;
|
|
55
|
+
let seen;
|
|
56
|
+
globalThis.fetch = async (url, init) => {
|
|
57
|
+
seen = { url: String(url), auth: init.headers.Authorization, body: JSON.parse(init.body) };
|
|
58
|
+
return new Response('{"id":"list-1"}', { status: 200 });
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
const client = new GoogleTasksClient({
|
|
62
|
+
accessToken: "SECRET",
|
|
63
|
+
apiBase: "https://tasks.googleapis.com",
|
|
64
|
+
timeoutMs: 1000,
|
|
65
|
+
maxRetries: 0,
|
|
66
|
+
});
|
|
67
|
+
await client.createTaskList("Smoke");
|
|
68
|
+
assert.equal(seen.url, "https://tasks.googleapis.com/tasks/v1/users/@me/lists");
|
|
69
|
+
assert.equal(seen.auth, "Bearer SECRET");
|
|
70
|
+
assert.deepEqual(seen.body, { title: "Smoke" });
|
|
71
|
+
} finally {
|
|
72
|
+
globalThis.fetch = original;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("dist registers the expected tools", () => {
|
|
77
|
+
const names = [];
|
|
78
|
+
const server = {
|
|
79
|
+
registerTool(name) {
|
|
80
|
+
names.push(name);
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
const client = {};
|
|
84
|
+
|
|
85
|
+
registerTaskListTools(server, client);
|
|
86
|
+
registerTaskTools(server, client);
|
|
87
|
+
registerCompletionTools(server, client);
|
|
88
|
+
registerRawTool(server, client);
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(names.sort(), ALL_TOOLS);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("dist binary completes a real MCP handshake over stdio and lists every tool", async () => {
|
|
94
|
+
const transport = new StdioClientTransport({
|
|
95
|
+
command: process.execPath,
|
|
96
|
+
args: [fileURLToPath(new URL("../dist/index.js", import.meta.url))],
|
|
97
|
+
env: {
|
|
98
|
+
...process.env,
|
|
99
|
+
GOOGLE_TASKS_ACCESS_TOKEN: "test-token",
|
|
100
|
+
ASKADS_TELEMETRY: "0", // keep the suite offline
|
|
101
|
+
},
|
|
102
|
+
stderr: "pipe",
|
|
103
|
+
});
|
|
104
|
+
const client = new Client({ name: "dist-smoke", version: "0.0.0" });
|
|
105
|
+
await client.connect(transport);
|
|
106
|
+
try {
|
|
107
|
+
const server = client.getServerVersion();
|
|
108
|
+
assert.equal(server?.name, "mcp-google-tasks");
|
|
109
|
+
assert.match(String(server?.version), /^\d+\.\d+\.\d+$/);
|
|
110
|
+
|
|
111
|
+
// The instructions the calling model reads before it picks any tool.
|
|
112
|
+
const instructions = client.getInstructions();
|
|
113
|
+
assert.equal(typeof instructions, "string");
|
|
114
|
+
assert.ok(instructions.trim().length > 0, "initialize result carries no instructions");
|
|
115
|
+
assert.match(instructions, /Google Tasks API v1/);
|
|
116
|
+
|
|
117
|
+
const { tools } = await client.listTools();
|
|
118
|
+
assert.deepEqual(tools.map((t) => t.name).sort(), ALL_TOOLS);
|
|
119
|
+
|
|
120
|
+
const listTasks = tools.find((t) => t.name === "list_tasks");
|
|
121
|
+
assert.equal(listTasks.annotations?.readOnlyHint, true);
|
|
122
|
+
assert.ok(listTasks.inputSchema?.properties?.tasklist_id, "input schema must reach the client");
|
|
123
|
+
|
|
124
|
+
// The reversible/destructive split must be visible to every MCP client.
|
|
125
|
+
const completeTask = tools.find((t) => t.name === "complete_task");
|
|
126
|
+
assert.equal(completeTask.annotations?.idempotentHint, true);
|
|
127
|
+
const deleteTask = tools.find((t) => t.name === "delete_task");
|
|
128
|
+
assert.equal(deleteTask.annotations?.destructiveHint, true);
|
|
129
|
+
} finally {
|
|
130
|
+
await client.close();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The degraded-start contract: without any credentials the binary must not
|
|
136
|
+
* exit(1) before the handshake, leaving the client a dead server and no reason.
|
|
137
|
+
* It must start, list every tool, open the instructions with the fix, and
|
|
138
|
+
* answer a tool call with the actionable error — offline: the CredentialsError
|
|
139
|
+
* fires before any fetch, so this test never touches the network.
|
|
140
|
+
*/
|
|
141
|
+
test("dist binary starts without credentials: handshake, tool list, actionable call error", async () => {
|
|
142
|
+
const env = Object.fromEntries(
|
|
143
|
+
Object.entries(process.env).filter(
|
|
144
|
+
([key, value]) => value !== undefined && !key.startsWith("GOOGLE_TASKS_"),
|
|
145
|
+
),
|
|
146
|
+
);
|
|
147
|
+
env.ASKADS_TELEMETRY = "0"; // keep the suite offline
|
|
148
|
+
const transport = new StdioClientTransport({
|
|
149
|
+
command: process.execPath,
|
|
150
|
+
args: [fileURLToPath(new URL("../dist/index.js", import.meta.url))],
|
|
151
|
+
env,
|
|
152
|
+
stderr: "pipe",
|
|
153
|
+
});
|
|
154
|
+
const client = new Client({ name: "dist-smoke-unconfigured", version: "0.0.0" });
|
|
155
|
+
await client.connect(transport);
|
|
156
|
+
try {
|
|
157
|
+
// The model must read the fix before it picks a tool.
|
|
158
|
+
const instructions = client.getInstructions() ?? "";
|
|
159
|
+
assert.match(instructions, /not connected/);
|
|
160
|
+
assert.match(instructions, /GOOGLE_TASKS_CLIENT_ID/);
|
|
161
|
+
assert.match(instructions, /restart/);
|
|
162
|
+
|
|
163
|
+
const { tools } = await client.listTools();
|
|
164
|
+
assert.deepEqual(tools.map((t) => t.name).sort(), ALL_TOOLS);
|
|
165
|
+
|
|
166
|
+
// A tool call fails with the exact message instead of killing the server.
|
|
167
|
+
const result = await client.callTool({ name: "list_tasklists", arguments: {} });
|
|
168
|
+
assert.equal(result.isError, true);
|
|
169
|
+
const text = result.content.map((c) => c.text ?? "").join(" ");
|
|
170
|
+
assert.match(text, /Google OAuth credentials are required: set GOOGLE_TASKS_CLIENT_ID/);
|
|
171
|
+
assert.match(text, /restart the server/);
|
|
172
|
+
} finally {
|
|
173
|
+
await client.close();
|
|
174
|
+
}
|
|
175
|
+
});
|