Skip to content

Commit cffcc73

Browse files
committed
fix: create proper tool arguments schema
1 parent 8e85d38 commit cffcc73

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

dev/graphql.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,15 @@ const yoga = createYoga({ schema });
274274
// Start server with proper request handler
275275
const server = Bun.serve({
276276
port: 4000,
277-
fetch: (request) => yoga.fetch(request),
277+
fetch: (request) => {
278+
// Add dev logger for incoming requests
279+
console.log(
280+
`[${new Date().toISOString()}] Incoming request: ${request.method} ${
281+
request.url
282+
}`
283+
);
284+
return yoga.fetch(request);
285+
},
278286
});
279287

280288
console.info(

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const server = new Server(
3333
server.setRequestHandler(ListToolsRequestSchema, async (request) => {
3434
await handler.loadTools();
3535

36-
console.error(handler.tools);
37-
3836
const tools = Array.from(handler.tools.values()).map((tool) => ({
3937
name: tool.name,
4038
description: tool.description,
@@ -56,8 +54,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
5654
};
5755
}
5856

57+
console.error("tool call", request.params.arguments);
58+
5959
const parsedArguments = tool.parameters.parse(request.params.arguments);
6060

61+
console.error("parsed arguments", parsedArguments);
62+
6163
const result = await handler.execute(
6264
parsedArguments.query,
6365
parsedArguments.variables

src/lib/graphql.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,6 @@ export function getOperations(
102102
} satisfies Operation),
103103
parameters: field.args,
104104
});
105-
106-
if (fieldName === "commentsByPost") {
107-
console.error(
108-
createOperationDescription(schema, {
109-
name: fieldName,
110-
type: "query",
111-
parameters: field.args,
112-
description: field.description,
113-
} satisfies Operation)
114-
);
115-
}
116105
}
117106
}
118107

@@ -190,7 +179,10 @@ function buildZodSchemaFromVariables(
190179
schemaObj[definition.name] = argumentToZodSchema(definition);
191180
}
192181

193-
return z.object(schemaObj);
182+
return z.object({
183+
variables: z.object(schemaObj),
184+
query: z.string(),
185+
});
194186
}
195187

196188
function argumentToZodSchema(argument: GraphQLArgument): z.ZodTypeAny {
@@ -292,11 +284,15 @@ export async function createGraphQLHandler(config: Config) {
292284
tools,
293285
loadTools,
294286
async execute(query: string, variables: unknown) {
287+
const body = JSON.stringify({ query, variables });
288+
console.error("body", body);
295289
const result = await fetch(config.endpoint, {
296290
method: "POST",
297-
body: JSON.stringify({ query, variables }),
291+
body,
298292
});
299293

294+
console.error("result", await result.json());
295+
300296
return {
301297
status: "success",
302298
data: await result.json(),

0 commit comments

Comments
 (0)