-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathserver.ts
More file actions
220 lines (206 loc) · 6.99 KB
/
server.ts
File metadata and controls
220 lines (206 loc) · 6.99 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env node
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { z } from "zod"
import { version } from "../package.json"
import { getRequiredEnv } from "./env"
import { orderSchema, sortSchema } from "./schema"
import { ApiClient } from "./api"
import { stringify } from "yaml"
import { formatTool } from "./formatTool"
import { searchQueryDocument } from "./guide/search-query"
export const createServer = () => {
const server = new McpServer({
name: "esa-server",
version: version,
})
const client = new ApiClient(getRequiredEnv("ESA_API_KEY"))
server.tool(
"get_search_query_document",
"Retrieves comprehensive documentation about esa.io search queries. Provides detailed information about available query syntax, operators, and search parameters to effectively search through esa posts.",
{},
async () => {
return {
content: [
{
type: "text",
text: searchQueryDocument,
},
],
}
}
)
server.tool(
"search_esa_posts",
"Search posts in esa.io. Response is paginated. " +
"For efficient search, you can use customized queries like the following: " +
'keyword for partial match, "keyword" for exact match, ' +
"keyword1 keyword2 for AND match, " +
"keyword1 OR keyword2 for OR match, " +
"-keyword for excluding keywords, " +
"title:keyword for title match, " +
"wip:true or wip:false for WIP posts, " +
"kind:stock or kind:flow for kind match, " +
"category:category_name for partial match with category name, " +
"in:category_name for prefix match with category name, " +
"on:category_name for exact match with category name, " +
"body:keyword for body match, " +
"tag:tag_name or tag:tag_name case_sensitive:true for tag match, " +
"user:screen_name for post author's screen name, " +
"updated_by:screen_name for post updater's screen name, " +
"comment:keyword for partial match with comments, " +
"starred:true or starred:false for starred posts, " +
"watched:true or watched:false for watched posts, " +
"watched_by:screen_name for screen name of members watching the post, " +
"sharing:true or sharing:false for shared posts, " +
"stars:>3 for posts with more than 3 stars, " +
"watches:>3 for posts with more than 3 watches, " +
"comments:>3 for posts with more than 3 comments, " +
"done:>=3 for posts with 3 or more done items, " +
"undone:>=3 for posts with 3 or more undone items, " +
"created:>YYYY-MM-DD for filtering by creation date, " +
"updated:>YYYY-MM-DD for filtering by update date." +
"Strongly recommend see get_search_query_document for complete query usage.",
{
teamName: z.string().default(getRequiredEnv("DEFAULT_ESA_TEAM")),
query: z.string(),
order: orderSchema,
sort: sortSchema,
page: z.number().min(1).default(1),
perPage: z.number().min(1).max(100).default(50),
},
async (input) =>
await formatTool(async () => {
const posts = await client.searchPosts(
input.teamName,
input.query,
input.order,
input.sort,
input.page,
input.perPage
)
return {
content: [
{
type: "text",
text: stringify({
posts: posts,
nextPage: input.page + 1,
}),
},
],
}
})
)
server.tool(
"read_esa_post",
"Read a post in esa.io.",
{
teamName: z.string().default(getRequiredEnv("DEFAULT_ESA_TEAM")),
postNumber: z.number(),
},
async (input) =>
await formatTool(async () => {
const [response] = await client.readPosts(input.teamName, [
input.postNumber,
])
if (response === undefined) {
throw new Error("post not found")
}
return response
})
)
server.tool(
"read_esa_multiple_posts",
"Read multiple posts in esa.io.",
{
teamName: z.string().default(getRequiredEnv("DEFAULT_ESA_TEAM")),
postNumbers: z.array(z.number()),
},
async (input) =>
await formatTool(
async () => await client.readPosts(input.teamName, input.postNumbers)
)
)
server.tool(
"create_esa_post",
"Create a new post in esa.io. Required parameters: name. Optional parameters: body_md, tags, category, wip (default: true), message.",
{
teamName: z.string().default(getRequiredEnv("DEFAULT_ESA_TEAM")),
name: z.string(),
body_md: z.string().optional(),
tags: z.array(z.string()).optional(),
category: z.string().optional(),
wip: z.boolean().default(true),
message: z.string().optional(),
},
async (input) =>
await formatTool(async () => {
const { teamName: createTeamName, ...postData } = input
return client.createPost(createTeamName, postData).then((data) => ({
success: true,
number: data.number,
full_name: data.full_name,
url: data.url,
wip: data.wip,
created_at: data.created_at,
message: data.message,
kind: data.kind,
tags: data.tags,
category: data.category,
revision_number: data.revision_number,
created_by: data.created_by,
}))
})
)
server.tool(
"update_esa_post",
"Update an existing post in esa.io. Required parameters: postNumber. Optional parameters: name, body_md, tags, category, wip, message.",
{
teamName: z.string().default(getRequiredEnv("DEFAULT_ESA_TEAM")),
postNumber: z.number(),
name: z.string().optional(),
body_md: z.string().optional(),
tags: z.array(z.string()).optional(),
category: z.string().optional(),
wip: z.boolean().optional(),
message: z.string().optional(),
},
async (input) =>
await formatTool(async () => {
const { teamName, postNumber, ...updateData } = input
return client
.updatePost(teamName, postNumber, updateData)
.then((data) => ({
success: true,
number: data.number,
full_name: data.full_name,
url: data.url,
wip: data.wip,
created_at: data.created_at,
updated_at: data.updated_at,
message: data.message,
kind: data.kind,
tags: data.tags,
category: data.category,
revision_number: data.revision_number,
created_by: data.created_by,
updated_by: data.updated_by,
}))
})
)
server.tool(
"delete_esa_post",
"Delete a post in esa.io. Required parameters: postNumber.",
{
teamName: z.string().default(getRequiredEnv("DEFAULT_ESA_TEAM")),
postNumber: z.number(),
},
async (input) =>
await formatTool(async () =>
client.deletePost(input.teamName, input.postNumber)
)
)
return {
server,
}
}