Skip to content

Commit 2fda514

Browse files
committed
refactor: update parameters definition to improve type inference
1 parent fe500bc commit 2fda514

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ You can also implement MCP tools using classes:
5252

5353
```typescript
5454
import { McpServer, type McpTool } from 'simple-mcp';
55-
import { z } from 'zod';
55+
import { z, ZodObject } from 'zod';
5656

57-
const parameters = z.object({
57+
const parameters = {
5858
name: z.string().describe('The name is required'),
59-
});
59+
};
6060

61-
class GreetTool implements McpTool<typeof parameters.shape> {
61+
class GreetTool implements McpTool<typeof parameters> {
6262
public readonly name = 'greet';
63-
public readonly parameters = parameters.shape;
63+
public readonly parameters = parameters;
6464

65-
public async execute({ name }: z.infer<typeof parameters>) {
65+
public async execute({ name }: z.infer<ZodObject<typeof this.parameters>>) {
6666
return {
6767
content: [
6868
{

examples/greet-class.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { McpServer, type McpTool } from 'simple-mcp';
2-
import { z } from 'zod';
2+
import { z, ZodObject } from 'zod';
33

4-
const parameters = z.object({
4+
const parameters = {
55
name: z.string().describe('The name is required'),
6-
});
6+
};
77

88
/**
99
* GreetTool class implements the McpTool interface
1010
* This demonstrates how to create an MCP tool using a class-based approach
1111
*/
12-
class GreetTool implements McpTool<typeof parameters.shape> {
12+
class GreetTool implements McpTool<typeof parameters> {
1313
// Tool name
1414
public readonly name = 'greet';
1515

1616
// Define parameters with Zod schema
17-
public readonly parameters = parameters.shape;
17+
public readonly parameters = parameters;
1818

1919
/**
2020
* Execute method that will be called when the tool is invoked
2121
* @param request The validated request parameters
2222
*/
23-
public async execute({ name }: z.infer<typeof parameters>) {
23+
public async execute({ name }: z.infer<ZodObject<typeof this.parameters>>) {
2424
return {
2525
content: [
2626
{

0 commit comments

Comments
 (0)