@esaio/esa-mcp-server 0.2.0 → 0.2.2

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.
Files changed (78) hide show
  1. package/README.en.md +10 -6
  2. package/README.md +16 -12
  3. package/bin/{index.js → index.mjs} +1 -1
  4. package/package.json +22 -3
  5. package/.dockerignore +0 -36
  6. package/.github/dependabot.yml +0 -23
  7. package/.github/workflows/docker-publish.yml +0 -120
  8. package/.github/workflows/main.yml +0 -41
  9. package/CLAUDE.md +0 -94
  10. package/Dockerfile +0 -34
  11. package/biome.json +0 -57
  12. package/src/__tests__/fixtures/mock-comment.ts +0 -90
  13. package/src/__tests__/fixtures/mock-post.ts +0 -79
  14. package/src/__tests__/index.test.ts +0 -216
  15. package/src/api_client/__tests__/index.test.ts +0 -149
  16. package/src/api_client/__tests__/middleware.test.ts +0 -120
  17. package/src/api_client/__tests__/with-context.test.ts +0 -98
  18. package/src/api_client/index.ts +0 -29
  19. package/src/api_client/middleware.ts +0 -21
  20. package/src/api_client/with-context.ts +0 -26
  21. package/src/config/__tests__/index.test.ts +0 -65
  22. package/src/config/index.ts +0 -20
  23. package/src/context/mcp-context.ts +0 -1
  24. package/src/context/stdio-context.ts +0 -6
  25. package/src/errors/missing-team-name-error.ts +0 -8
  26. package/src/formatters/__tests__/mcp-response.test.ts +0 -106
  27. package/src/formatters/mcp-response.ts +0 -95
  28. package/src/generated/api-types.ts +0 -2968
  29. package/src/i18n/__tests__/index.test.ts +0 -53
  30. package/src/i18n/index.ts +0 -39
  31. package/src/index.ts +0 -47
  32. package/src/locales/en.json +0 -13
  33. package/src/locales/ja.json +0 -13
  34. package/src/prompts/__tests__/index.test.ts +0 -48
  35. package/src/prompts/__tests__/summarize-post.test.ts +0 -291
  36. package/src/prompts/index.ts +0 -21
  37. package/src/prompts/summarize-post.ts +0 -94
  38. package/src/resources/__tests__/index.test.ts +0 -50
  39. package/src/resources/__tests__/recent-posts-list.test.ts +0 -92
  40. package/src/resources/__tests__/recent-posts.test.ts +0 -270
  41. package/src/resources/index.ts +0 -33
  42. package/src/resources/recent-posts-list.ts +0 -22
  43. package/src/resources/recent-posts.ts +0 -45
  44. package/src/schemas/team-name-schema.ts +0 -19
  45. package/src/tools/__tests__/attachments.test.ts +0 -460
  46. package/src/tools/__tests__/categories.test.ts +0 -402
  47. package/src/tools/__tests__/comments.test.ts +0 -970
  48. package/src/tools/__tests__/helps.test.ts +0 -222
  49. package/src/tools/__tests__/index.test.ts +0 -48
  50. package/src/tools/__tests__/post-actions.test.ts +0 -445
  51. package/src/tools/__tests__/posts.test.ts +0 -917
  52. package/src/tools/__tests__/search.test.ts +0 -339
  53. package/src/tools/__tests__/teams.test.ts +0 -615
  54. package/src/tools/attachments.ts +0 -167
  55. package/src/tools/categories.ts +0 -153
  56. package/src/tools/comments.ts +0 -258
  57. package/src/tools/helps.ts +0 -50
  58. package/src/tools/index.ts +0 -351
  59. package/src/tools/post-actions.ts +0 -132
  60. package/src/tools/posts.ts +0 -179
  61. package/src/tools/search.ts +0 -98
  62. package/src/tools/teams.ts +0 -157
  63. package/src/transformers/__tests__/category-transformer.test.ts +0 -161
  64. package/src/transformers/__tests__/comment-transformer.test.ts +0 -129
  65. package/src/transformers/__tests__/post-name-normalizer.test.ts +0 -53
  66. package/src/transformers/__tests__/post-transformer.test.ts +0 -70
  67. package/src/transformers/__tests__/query-normalizer.test.ts +0 -98
  68. package/src/transformers/__tests__/team-name-normalizer.test.ts +0 -21
  69. package/src/transformers/category-transformer.ts +0 -36
  70. package/src/transformers/comment-transformer.ts +0 -34
  71. package/src/transformers/post-name-normalizer.ts +0 -30
  72. package/src/transformers/post-transformer.ts +0 -38
  73. package/src/transformers/query-normalizer.ts +0 -36
  74. package/src/transformers/team-name-normalizer.ts +0 -7
  75. package/tsconfig.build.json +0 -4
  76. package/tsconfig.json +0 -30
  77. package/tsdown.config.ts +0 -13
  78. package/vitest.config.ts +0 -24
@@ -1,92 +0,0 @@
1
- import type { MockInstance } from "vitest";
2
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3
- import { withContext } from "../../api_client/with-context.js";
4
- import type { MCPContext } from "../../context/mcp-context.js";
5
- import { getTeams } from "../../tools/teams.js";
6
- import { createRecentPostsResourceList } from "../recent-posts-list.js";
7
-
8
- vi.mock("../../api_client/with-context.js");
9
- vi.mock("../../tools/teams.js");
10
-
11
- describe("createRecentPostsResourceList", () => {
12
- let context: MCPContext;
13
- let consoleErrorSpy: MockInstance<typeof console.error>;
14
-
15
- beforeEach(() => {
16
- context = {} as unknown as MCPContext;
17
- consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
18
- vi.clearAllMocks();
19
- });
20
-
21
- afterEach(() => {
22
- consoleErrorSpy.mockRestore();
23
- });
24
-
25
- it("should return team resources when teams are available", async () => {
26
- const mockTeams = {
27
- teams: [
28
- { name: "team1", description: "Team One" },
29
- { name: "team2", description: "" },
30
- ],
31
- };
32
-
33
- vi.mocked(withContext).mockResolvedValue({
34
- content: [{ text: JSON.stringify(mockTeams) }],
35
- } as unknown as Awaited<ReturnType<typeof withContext>>);
36
-
37
- const result = await createRecentPostsResourceList(context);
38
-
39
- expect(withContext).toHaveBeenCalledWith(context, getTeams, {});
40
- expect(result).toEqual([
41
- {
42
- uri: "esa://teams/team1/posts/recent",
43
- name: "Recent posts from team1",
44
- description: "Recent posts from team1 (Team One)",
45
- mimeType: "application/json",
46
- },
47
- {
48
- uri: "esa://teams/team2/posts/recent",
49
- name: "Recent posts from team2",
50
- description: "Recent posts from team2",
51
- mimeType: "application/json",
52
- },
53
- ]);
54
- });
55
-
56
- it("should return empty array when no teams available", async () => {
57
- vi.mocked(withContext).mockResolvedValue({
58
- content: [{ text: JSON.stringify({ teams: null }) }],
59
- } as unknown as Awaited<ReturnType<typeof withContext>>);
60
-
61
- const result = await createRecentPostsResourceList(context);
62
-
63
- expect(result).toEqual([]);
64
- });
65
-
66
- it("should return empty array and log error when withContext fails", async () => {
67
- const error = new Error("API Error");
68
- vi.mocked(withContext).mockRejectedValue(error);
69
-
70
- const result = await createRecentPostsResourceList(context);
71
-
72
- expect(result).toEqual([]);
73
- expect(consoleErrorSpy).toHaveBeenCalledWith(
74
- "Failed to list teams:",
75
- error,
76
- );
77
- });
78
-
79
- it("should return empty array when JSON parsing fails", async () => {
80
- vi.mocked(withContext).mockResolvedValue({
81
- content: [{ text: "invalid json" }],
82
- } as unknown as Awaited<ReturnType<typeof withContext>>);
83
-
84
- const result = await createRecentPostsResourceList(context);
85
-
86
- expect(result).toEqual([]);
87
- expect(consoleErrorSpy).toHaveBeenCalledWith(
88
- "Failed to list teams:",
89
- expect.any(SyntaxError),
90
- );
91
- });
92
- });
@@ -1,270 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from "vitest";
2
- import {
3
- createExpectedTransformed,
4
- createLongContentPost,
5
- createMockPost,
6
- createNullBodyPost,
7
- createWipPost,
8
- } from "../../__tests__/fixtures/mock-post.js";
9
- import type { createEsaClient } from "../../api_client/index.js";
10
- import { getRecentPosts } from "../recent-posts.js";
11
-
12
- describe("getRecentPosts", () => {
13
- const mockClient = {
14
- GET: vi.fn(),
15
- } as unknown as ReturnType<typeof createEsaClient> & {
16
- GET: ReturnType<typeof vi.fn>;
17
- };
18
-
19
- const testUri = "esa://teams/test-team/posts/recent";
20
-
21
- beforeEach(() => {
22
- vi.clearAllMocks();
23
- });
24
-
25
- it("should return recent posts successfully", async () => {
26
- const mockPosts = [
27
- createMockPost({
28
- number: 1,
29
- name: "post1.md",
30
- full_name: "dev/post1.md #tag1 #tag2",
31
- body_md:
32
- "This is a test post content that is quite long and should be truncated",
33
- body_html: "<p>This is a test post content</p>",
34
- url: "https://test-team.esa.example.com/posts/1",
35
- comments_count: 3,
36
- tasks_count: 5,
37
- done_tasks_count: 2,
38
- watchers_count: 7,
39
- star: false,
40
- watch: false,
41
- }),
42
- createWipPost({
43
- number: 2,
44
- name: "post2.md",
45
- full_name: "docs/post2.md #wip",
46
- body_md: "Short content",
47
- body_html: "<p>Short content</p>",
48
- url: "https://test-team.esa.example.com/posts/2",
49
- created_at: "2024-01-03T00:00:00+09:00",
50
- updated_at: "2024-01-04T00:00:00+09:00",
51
- stargazers_count: 1,
52
- watchers_count: 2,
53
- star: true,
54
- watch: true,
55
- }),
56
- ];
57
-
58
- const mockResponse = {
59
- posts: mockPosts,
60
- page: 1,
61
- per_page: 20,
62
- total_count: 2,
63
- max_per_page: 100,
64
- };
65
-
66
- mockClient.GET.mockResolvedValue({
67
- data: mockResponse,
68
- error: undefined,
69
- response: {
70
- ok: true,
71
- status: 200,
72
- } as Response,
73
- });
74
-
75
- const result = await getRecentPosts(mockClient, {
76
- teamName: "test-team",
77
- uri: testUri,
78
- });
79
-
80
- expect(mockClient.GET).toHaveBeenCalledWith("/v1/teams/{team_name}/posts", {
81
- params: {
82
- path: { team_name: "test-team" },
83
- query: {
84
- sort: "updated",
85
- order: "desc",
86
- },
87
- },
88
- });
89
-
90
- const expectedResponse = {
91
- posts: mockPosts.map((post) => createExpectedTransformed(post)),
92
- page: 1,
93
- per_page: 20,
94
- total_count: 2,
95
- max_per_page: 100,
96
- };
97
-
98
- expect(result).toEqual({
99
- contents: [
100
- {
101
- uri: testUri,
102
- mimeType: "application/json",
103
- text: JSON.stringify(expectedResponse, null, 2),
104
- },
105
- ],
106
- });
107
- });
108
-
109
- it("should truncate long body_md content", async () => {
110
- const mockPost = createLongContentPost(600);
111
-
112
- mockClient.GET.mockResolvedValue({
113
- data: { posts: [mockPost] },
114
- error: undefined,
115
- response: {
116
- ok: true,
117
- status: 200,
118
- } as Response,
119
- });
120
-
121
- const result = await getRecentPosts(mockClient, {
122
- teamName: "test-team",
123
- uri: testUri,
124
- });
125
-
126
- const parsedResult = JSON.parse(result.contents[0].text as string);
127
- expect(parsedResult.posts[0].body_md).toBe(`${"a".repeat(500)}...`);
128
- });
129
-
130
- it("should handle empty posts array", async () => {
131
- mockClient.GET.mockResolvedValue({
132
- data: {
133
- posts: [],
134
- page: 1,
135
- per_page: 20,
136
- total_count: 0,
137
- max_per_page: 100,
138
- },
139
- error: undefined,
140
- response: {
141
- ok: true,
142
- status: 200,
143
- } as Response,
144
- });
145
-
146
- const result = await getRecentPosts(mockClient, {
147
- teamName: "test-team",
148
- uri: testUri,
149
- });
150
-
151
- const parsedResult = JSON.parse(result.contents[0].text as string);
152
- expect(parsedResult.posts).toEqual([]);
153
- expect(parsedResult.total_count).toBe(0);
154
- });
155
-
156
- it("should handle API errors", async () => {
157
- const mockError = { error: "unauthorized", message: "Invalid token" };
158
-
159
- mockClient.GET.mockResolvedValue({
160
- data: undefined,
161
- error: mockError,
162
- response: {
163
- ok: false,
164
- status: 404,
165
- } as Response,
166
- });
167
-
168
- const result = await getRecentPosts(mockClient, {
169
- teamName: "test-team",
170
- uri: testUri,
171
- });
172
-
173
- expect(result).toEqual({
174
- contents: [
175
- {
176
- uri: testUri,
177
- mimeType: "application/json",
178
- text: `Error: ${JSON.stringify(mockError, null, 2)}`,
179
- },
180
- ],
181
- });
182
- });
183
-
184
- it("should handle response status errors", async () => {
185
- mockClient.GET.mockResolvedValue({
186
- data: undefined,
187
- error: undefined,
188
- response: {
189
- ok: false,
190
- status: 500,
191
- } as Response,
192
- });
193
-
194
- const result = await getRecentPosts(mockClient, {
195
- teamName: "test-team",
196
- uri: testUri,
197
- });
198
-
199
- expect(result).toEqual({
200
- contents: [
201
- {
202
- uri: testUri,
203
- mimeType: "application/json",
204
- text: "Error: API Response(status: 500)",
205
- },
206
- ],
207
- });
208
- });
209
-
210
- it("should handle network errors", async () => {
211
- const networkError = new Error("Network connection failed");
212
-
213
- mockClient.GET.mockRejectedValue(networkError);
214
-
215
- const result = await getRecentPosts(mockClient, {
216
- teamName: "test-team",
217
- uri: testUri,
218
- });
219
-
220
- expect(result).toEqual({
221
- contents: [
222
- {
223
- uri: testUri,
224
- mimeType: "application/json",
225
- text: "Error: Network connection failed",
226
- },
227
- ],
228
- });
229
- });
230
-
231
- it("should handle non-Error exceptions", async () => {
232
- mockClient.GET.mockRejectedValue("Unexpected error");
233
-
234
- const result = await getRecentPosts(mockClient, {
235
- teamName: "test-team",
236
- uri: testUri,
237
- });
238
-
239
- expect(result).toEqual({
240
- contents: [
241
- {
242
- uri: testUri,
243
- mimeType: "application/json",
244
- text: "Error: Unexpected error",
245
- },
246
- ],
247
- });
248
- });
249
-
250
- it("should handle posts with undefined body_md", async () => {
251
- const mockPost = createNullBodyPost();
252
-
253
- mockClient.GET.mockResolvedValue({
254
- data: { posts: [mockPost] },
255
- error: undefined,
256
- response: {
257
- ok: true,
258
- status: 200,
259
- } as Response,
260
- });
261
-
262
- const result = await getRecentPosts(mockClient, {
263
- teamName: "test-team",
264
- uri: testUri,
265
- });
266
-
267
- const parsedResult = JSON.parse(result.contents[0].text as string);
268
- expect(parsedResult.posts[0].body_md).toBe(undefined);
269
- });
270
- });
@@ -1,33 +0,0 @@
1
- import {
2
- type McpServer,
3
- ResourceTemplate,
4
- } from "@modelcontextprotocol/sdk/server/mcp.js";
5
- import { withContext } from "../api_client/with-context.js";
6
- import type { MCPContext } from "../context/mcp-context.js";
7
-
8
- import { getRecentPosts } from "./recent-posts.js";
9
- import { createRecentPostsResourceList } from "./recent-posts-list.js";
10
-
11
- export function setupResources(server: McpServer, context: MCPContext): void {
12
- console.error("Setting up MCP resources...");
13
-
14
- server.registerResource(
15
- "esa_recent_posts",
16
- new ResourceTemplate("esa://teams/{teamName}/posts/recent", {
17
- list: async () => {
18
- const resources = await createRecentPostsResourceList(context);
19
- return { resources };
20
- },
21
- }),
22
- {
23
- title: "Recent Posts",
24
- description: "Fetch recent updated posts from esa team",
25
- mimeType: "application/json",
26
- },
27
- async (uri, params) =>
28
- withContext(context, getRecentPosts, { ...params, uri: uri.href } as {
29
- teamName: string;
30
- uri: string;
31
- }),
32
- );
33
- }
@@ -1,22 +0,0 @@
1
- import { withContext } from "../api_client/with-context.js";
2
- import type { MCPContext } from "../context/mcp-context.js";
3
- import { getTeams } from "../tools/teams.js";
4
-
5
- export async function createRecentPostsResourceList(context: MCPContext) {
6
- try {
7
- const result = await withContext(context, getTeams, {});
8
- const data = JSON.parse(result.content[0].text as string);
9
-
10
- return (
11
- data.teams?.map((team: { name: string; description: string }) => ({
12
- uri: `esa://teams/${team.name}/posts/recent`,
13
- name: `Recent posts from ${team.name}`,
14
- description: `Recent posts from ${team.name}${team.description ? ` (${team.description})` : ""}`,
15
- mimeType: "application/json",
16
- })) || []
17
- );
18
- } catch (error) {
19
- console.error("Failed to list teams:", error);
20
- return [];
21
- }
22
- }
@@ -1,45 +0,0 @@
1
- import type { createEsaClient } from "../api_client/index.js";
2
- import {
3
- formatResourceError,
4
- formatResourceResponse,
5
- } from "../formatters/mcp-response.js";
6
- import type { components } from "../generated/api-types.js";
7
- import { transformPost } from "../transformers/post-transformer.js";
8
-
9
- const RECENT_POSTS_QUERY = {
10
- sort: "updated",
11
- order: "desc",
12
- } as const;
13
-
14
- export async function getRecentPosts(
15
- client: ReturnType<typeof createEsaClient>,
16
- args: { teamName: string; uri: string },
17
- ) {
18
- const { teamName, uri } = args;
19
- try {
20
- const { data, error, response } = await client.GET(
21
- "/v1/teams/{team_name}/posts",
22
- {
23
- params: {
24
- path: { team_name: teamName },
25
- query: RECENT_POSTS_QUERY,
26
- },
27
- },
28
- );
29
-
30
- if (error || !response.ok) {
31
- return formatResourceError(error || response.status, uri);
32
- }
33
-
34
- const transformed = {
35
- ...data,
36
- posts: data.posts?.map((post: components["schemas"]["Post"]) =>
37
- transformPost(post, { truncateBody: 500 }),
38
- ),
39
- };
40
-
41
- return formatResourceResponse(transformed, uri);
42
- } catch (error) {
43
- return formatResourceError(error, uri);
44
- }
45
- }
@@ -1,19 +0,0 @@
1
- import { z } from "zod";
2
- import { normalizeTeamName } from "../transformers/team-name-normalizer.js";
3
-
4
- export const teamNameSchema = z
5
- .string()
6
- .default("")
7
- .describe(
8
- "Team name (required). Use esa_get_teams first to see available teams.",
9
- )
10
- .transform(normalizeTeamName);
11
-
12
- export function createSchemaWithTeamName<T extends z.ZodRawShape>(
13
- schema: T,
14
- ): z.ZodObject<T & { teamName: typeof teamNameSchema }> {
15
- return z.object({
16
- teamName: teamNameSchema,
17
- ...schema,
18
- });
19
- }