Skip to content

Commit 43d3d46

Browse files
refactor(tools): add type annotations to async parameters in tools
1 parent 526f9c3 commit 43d3d46

File tree

7 files changed

+156
-28
lines changed

7 files changed

+156
-28
lines changed

tools/blobTools.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function registerBlobTools(server: McpServer, config: Config) {
1212
{
1313
prefix: z.string().optional().describe("If specified, only include blobs that start with this string"),
1414
},
15-
async ({prefix}) => {
15+
async ({prefix}: {prefix: string}) => {
1616
try {
1717
const queryParams = prefix ? `?prefix=${encodeURIComponent(prefix)}` : ""
1818
const data = await callValTownApi(config, `/v1/blob${queryParams}`)
@@ -36,7 +36,7 @@ export function registerBlobTools(server: McpServer, config: Config) {
3636
{
3737
key: z.string().min(1).max(512).describe("Key that uniquely identifies this blob"),
3838
},
39-
async ({key}) => {
39+
async ({key}: {key: string}) => {
4040
try {
4141
// For blobs, we need to handle binary data differently
4242
const url = `${config.apiBase}/v1/blob/${encodeURIComponent(key)}`
@@ -87,7 +87,12 @@ export function registerBlobTools(server: McpServer, config: Config) {
8787
isBase64: z.boolean().default(false).describe("Whether the data is base64-encoded binary"),
8888
contentType: z.string().default("text/plain").describe("Content type of the blob"),
8989
},
90-
async ({key, data, isBase64, contentType}) => {
90+
async ({key, data, isBase64, contentType}: {
91+
key: string
92+
data: string
93+
isBase64: boolean
94+
contentType: string
95+
}) => {
9196
try {
9297
// Convert from base64 if needed
9398
let bodyData = data
@@ -135,7 +140,7 @@ export function registerBlobTools(server: McpServer, config: Config) {
135140
{
136141
key: z.string().min(1).max(512).describe("Key that uniquely identifies this blob"),
137142
},
138-
async ({key}) => {
143+
async ({key}: {key: string}) => {
139144
try {
140145
await callValTownApi(config, `/v1/blob/${encodeURIComponent(key)}`, {
141146
method: "DELETE",

tools/branchTools.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export function registerBranchTools(server: McpServer, config: Config) {
1414
limit: z.number().int().min(1).max(100).default(20).describe("Maximum number of results to return"),
1515
offset: z.number().int().min(0).default(0).describe("Number of items to skip for pagination"),
1616
},
17-
async ({projectId, limit, offset}) => {
17+
async ({projectId, limit, offset}: {
18+
projectId: string
19+
limit: number
20+
offset: number
21+
}) => {
1822
try {
1923
const data = await callValTownApi(
2024
config,
@@ -41,7 +45,10 @@ export function registerBranchTools(server: McpServer, config: Config) {
4145
projectId: z.string().describe("ID of the project"),
4246
branchId: z.string().describe("ID of the branch"),
4347
},
44-
async ({projectId, branchId}) => {
48+
async ({projectId, branchId}: {
49+
projectId: string
50+
branchId: string
51+
}) => {
4552
try {
4653
const data = await callValTownApi(config, `/v1/projects/${projectId}/branches/${branchId}`)
4754

@@ -66,7 +73,11 @@ export function registerBranchTools(server: McpServer, config: Config) {
6673
name: z.string().describe("Name for the branch"),
6774
forkedBranchId: z.string().optional().describe("ID of branch to fork from (optional)"),
6875
},
69-
async ({projectId, name, forkedBranchId}) => {
76+
async ({projectId, name, forkedBranchId}: {
77+
projectId: string
78+
name: string
79+
forkedBranchId?: string
80+
}) => {
7081
try {
7182
const payload = {
7283
name,
@@ -98,7 +109,10 @@ export function registerBranchTools(server: McpServer, config: Config) {
98109
projectId: z.string().describe("ID of the project"),
99110
branchId: z.string().describe("ID of the branch to delete"),
100111
},
101-
async ({projectId, branchId}) => {
112+
async ({projectId, branchId}: {
113+
projectId: string
114+
branchId: string
115+
}) => {
102116
try {
103117
await callValTownApi(config, `/v1/projects/${projectId}/branches/${branchId}`, {
104118
method: "DELETE",

tools/fileTools.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ export function registerFileTools(server: McpServer, config: Config) {
1717
limit: z.number().int().min(1).max(100).default(20).describe("Maximum number of results to return"),
1818
offset: z.number().int().min(0).default(0).describe("Number of items to skip for pagination"),
1919
},
20-
async ({projectId, path, branchId, recursive, limit, offset}) => {
20+
async ({projectId, path, branchId, recursive, limit, offset}: {
21+
projectId: string
22+
path: string
23+
branchId?: string
24+
recursive: boolean
25+
limit: number
26+
offset: number
27+
}) => {
2128
try {
2229
let endpoint = `/v1/projects/${projectId}/files`
2330
if (path) {
@@ -55,7 +62,11 @@ export function registerFileTools(server: McpServer, config: Config) {
5562
path: z.string().describe("Path to the file"),
5663
branchId: z.string().optional().describe("ID of the branch (optional, defaults to main)"),
5764
},
58-
async ({projectId, path, branchId}) => {
65+
async ({projectId, path, branchId}: {
66+
projectId: string
67+
path: string
68+
branchId?: string
69+
}) => {
5970
try {
6071
let endpoint = `/v1/projects/${projectId}/files/${encodeURIComponent(path)}/content`
6172
if (branchId) {
@@ -98,11 +109,18 @@ export function registerFileTools(server: McpServer, config: Config) {
98109
{
99110
projectId: z.string().describe("ID of the project"),
100111
path: z.string().describe("Path to the new file or directory"),
101-
type: z.enum(["file", "directory"]).describe("Type of resource to create"),
112+
type: z.enum(["file", "interval", "http", "email", "script", "directory"])
113+
.describe("Type of resource to create: file, interval, http, email, script, or directory"),
102114
content: z.string().optional().describe("Content for the file (required for files, not for directories)"),
103115
branchId: z.string().optional().describe("ID of the branch (optional, defaults to main)"),
104116
},
105-
async ({projectId, path, type, content, branchId}) => {
117+
async ({projectId, path, type, content, branchId}: {
118+
projectId: string
119+
path: string
120+
type: "file" | "interval" | "http" | "email" | "script" | "directory"
121+
content?: string
122+
branchId?: string
123+
}) => {
106124
try {
107125
// Validate that content is provided for files
108126
if (type === "file" && content === undefined) {
@@ -149,7 +167,12 @@ export function registerFileTools(server: McpServer, config: Config) {
149167
content: z.string().describe("New content for the file"),
150168
branchId: z.string().optional().describe("ID of the branch (optional, defaults to main)"),
151169
},
152-
async ({projectId, path, content, branchId}) => {
170+
async ({projectId, path, content, branchId}: {
171+
projectId: string
172+
path: string
173+
content: string
174+
branchId?: string
175+
}) => {
153176
try {
154177
let endpoint = `/v1/projects/${projectId}/files/${encodeURIComponent(path)}`
155178
if (branchId) {
@@ -182,7 +205,11 @@ export function registerFileTools(server: McpServer, config: Config) {
182205
path: z.string().describe("Path to the file or directory"),
183206
branchId: z.string().optional().describe("ID of the branch (optional, defaults to main)"),
184207
},
185-
async ({projectId, path, branchId}) => {
208+
async ({projectId, path, branchId}: {
209+
projectId: string
210+
path: string
211+
branchId?: string
212+
}) => {
186213
try {
187214
let endpoint = `/v1/projects/${projectId}/files/${encodeURIComponent(path)}`
188215
if (branchId) {

tools/projectTools.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function registerProjectTools(server: McpServer, config: Config) {
1212
limit: z.number().int().min(1).max(100).default(20).describe("Maximum number of results to return"),
1313
offset: z.number().int().min(0).default(0).describe("Number of items to skip for pagination"),
1414
},
15-
async ({limit, offset}) => {
15+
async ({limit, offset}: {limit: number; offset: number}) => {
1616
try {
1717
const data = await callValTownApi(
1818
config,
@@ -39,7 +39,7 @@ export function registerProjectTools(server: McpServer, config: Config) {
3939
{
4040
projectId: z.string().describe("ID of the project"),
4141
},
42-
async ({projectId}) => {
42+
async ({projectId}: {projectId: string}) => {
4343
try {
4444
const data = await callValTownApi(config, `/v1/projects/${projectId}`)
4545

@@ -64,7 +64,7 @@ export function registerProjectTools(server: McpServer, config: Config) {
6464
username: z.string().describe("Username of the project's owner"),
6565
projectName: z.string().describe("Name of the project"),
6666
},
67-
async ({username, projectName}) => {
67+
async ({username, projectName}: {username: string; projectName: string}) => {
6868
try {
6969
const data = await callValTownApi(
7070
config,
@@ -95,7 +95,7 @@ export function registerProjectTools(server: McpServer, config: Config) {
9595
description: z.string().optional().describe("Description for the project (optional)"),
9696
imageUrl: z.string().optional().describe("URL to an image for the project (optional)"),
9797
},
98-
async ({name, privacy, description, imageUrl}) => {
98+
async ({name, privacy, description, imageUrl}: {name: string; privacy: "public" | "private"; description?: string; imageUrl?: string}) => {
9999
try {
100100
const payload = {
101101
name,
@@ -129,7 +129,7 @@ export function registerProjectTools(server: McpServer, config: Config) {
129129
{
130130
projectId: z.string().describe("ID of the project to delete"),
131131
},
132-
async ({projectId}) => {
132+
async ({projectId}: {projectId: string}) => {
133133
try {
134134
await callValTownApi(config, `/v1/projects/${projectId}`, {
135135
method: "DELETE",

tools/sqliteTools.ts

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function registerSqliteTools(server: McpServer, config: Config) {
1212
{
1313
statement: z.string().describe("SQL statement to execute"),
1414
},
15-
async ({statement}) => {
15+
async ({statement}: {statement: string}) => {
1616
try {
1717
const data = await callValTownApi(config, "/v1/sqlite/execute", {
1818
method: "POST",
@@ -39,7 +39,10 @@ export function registerSqliteTools(server: McpServer, config: Config) {
3939
statements: z.array(z.string()).describe("Array of SQL statements to execute"),
4040
mode: z.enum(["read", "write"]).default("read").describe("Mode of the statements (read or write)"),
4141
},
42-
async ({statements, mode}) => {
42+
async ({statements, mode}: {
43+
statements: string[]
44+
mode: "read" | "write"
45+
}) => {
4346
try {
4447
const data = await callValTownApi(config, "/v1/sqlite/batch", {
4548
method: "POST",
@@ -57,4 +60,60 @@ export function registerSqliteTools(server: McpServer, config: Config) {
5760
}
5861
}
5962
)
63+
64+
// Fix for sqlite-query function
65+
server.tool(
66+
"sqlite-query",
67+
"Execute a SQL query against a SQLite database",
68+
{
69+
statement: z.string().describe("SQL statement to execute"),
70+
},
71+
async ({statement}: {statement: string}) => {
72+
try {
73+
const data = await callValTownApi(config, "/v1/sqlite/query", {
74+
method: "POST",
75+
body: JSON.stringify({statement}),
76+
})
77+
78+
return {
79+
content: [{type: "text", text: JSON.stringify(data, null, 2)}],
80+
}
81+
} catch (error) {
82+
return {
83+
content: [{type: "text", text: `Error executing SQL query: ${getErrorMessage(error)}`}],
84+
isError: true,
85+
}
86+
}
87+
}
88+
)
89+
90+
// Fix for sqlite-exec function
91+
server.tool(
92+
"sqlite-exec",
93+
"Execute multiple SQL statements against a SQLite database",
94+
{
95+
statements: z.array(z.string()).describe("Array of SQL statements to execute"),
96+
mode: z.enum(["read", "write"]).default("read").describe("Mode of the statements (read or write)"),
97+
},
98+
async ({statements, mode}: {
99+
statements: string
100+
mode: string // or a more specific type if applicable
101+
}) => {
102+
try {
103+
const data = await callValTownApi(config, "/v1/sqlite/exec", {
104+
method: "POST",
105+
body: JSON.stringify({statements, mode}),
106+
})
107+
108+
return {
109+
content: [{type: "text", text: JSON.stringify(data, null, 2)}],
110+
}
111+
} catch (error) {
112+
return {
113+
content: [{type: "text", text: `Error executing SQL exec: ${getErrorMessage(error)}`}],
114+
isError: true,
115+
}
116+
}
117+
}
118+
)
60119
}

tools/userTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function registerUserTools(server: McpServer, config: Config) {
1212
{
1313
username: z.string().describe("Username of the user to look for (without @ symbol)"),
1414
},
15-
async ({username}) => {
15+
async ({username}: {username: string}) => {
1616
try {
1717
const data = await callValTownApi(config, `/v1/alias/${encodeURIComponent(username)}`)
1818

tools/valsTools.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export function registerValTools(server: McpServer, config: Config) {
1313
limit: z.number().int().min(1).max(100).default(20).describe("Maximum number of results to return"),
1414
offset: z.number().int().min(0).default(0).describe("Number of items to skip for pagination"),
1515
},
16-
async ({query, limit, offset}) => {
16+
async ({query, limit, offset}: {
17+
query: string
18+
limit: number
19+
offset: number
20+
}) => {
1721
try {
1822
const data = await callValTownApi(
1923
config,
@@ -41,7 +45,10 @@ export function registerValTools(server: McpServer, config: Config) {
4145
username: z.string().describe("Username of the val's owner"),
4246
valName: z.string().describe("Name of the val"),
4347
},
44-
async ({username, valName}) => {
48+
async ({username, valName}: {
49+
username: string
50+
valName: string
51+
}) => {
4552
try {
4653
const data = await callValTownApi(
4754
config,
@@ -74,7 +81,13 @@ export function registerValTools(server: McpServer, config: Config) {
7481
.describe("Type of val (script is for libraries or one-off calculations)"),
7582
readme: z.string().optional().describe("Markdown readme for the val (optional)"),
7683
},
77-
async ({name, code, privacy, type, readme}) => {
84+
async ({name, code, privacy, type, readme}: {
85+
name: string
86+
code: string
87+
privacy: "public" | "unlisted" | "private"
88+
type: "interval" | "http" | "express" | "email" | "script" | "rpc" | "httpnext"
89+
readme?: string
90+
}) => {
7891
try {
7992
const payload = {
8093
name,
@@ -116,7 +129,14 @@ export function registerValTools(server: McpServer, config: Config) {
116129
.describe("Type of val (optional)"),
117130
readme: z.string().optional().describe("Markdown readme for the val (optional)"),
118131
},
119-
async ({valId, ...updates}) => {
132+
async ({valId, ...updates}: {
133+
valId: string
134+
code?: string
135+
name?: string
136+
privacy?: "public" | "unlisted" | "private"
137+
type?: "interval" | "http" | "express" | "email" | "script" | "rpc" | "httpnext"
138+
readme?: string
139+
}) => {
120140
try {
121141
if (Object.keys(updates).length === 0) {
122142
return {
@@ -157,7 +177,10 @@ export function registerValTools(server: McpServer, config: Config) {
157177
valId: z.string().uuid().describe("ID of the val"),
158178
code: z.string().describe("New TypeScript code for the val"),
159179
},
160-
async ({valId, code}) => {
180+
async ({valId, code}: {
181+
valId: string
182+
code: string
183+
}) => {
161184
try {
162185
const data = await callValTownApi(config, `/v1/vals/${valId}/versions`, {
163186
method: "POST",
@@ -184,7 +207,7 @@ export function registerValTools(server: McpServer, config: Config) {
184207
{
185208
valId: z.string().uuid().describe("ID of the val to delete"),
186209
},
187-
async ({valId}) => {
210+
async ({valId}: {valId: string}) => {
188211
try {
189212
await callValTownApi(config, `/v1/vals/${valId}`, {
190213
method: "DELETE",

0 commit comments

Comments
 (0)