File tree 2 files changed +12
-12
lines changed
2 files changed +12
-12
lines changed Original file line number Diff line number Diff line change @@ -52,17 +52,17 @@ You can also implement MCP tools using classes:
52
52
53
53
``` typescript
54
54
import { McpServer , type McpTool } from ' simple-mcp' ;
55
- import { z } from ' zod' ;
55
+ import { z , ZodObject } from ' zod' ;
56
56
57
- const parameters = z . object ( {
57
+ const parameters = {
58
58
name: z .string ().describe (' The name is required' ),
59
- }) ;
59
+ };
60
60
61
- class GreetTool implements McpTool <typeof parameters . shape > {
61
+ class GreetTool implements McpTool <typeof parameters > {
62
62
public readonly name = ' greet' ;
63
- public readonly parameters = parameters . shape ;
63
+ public readonly parameters = parameters ;
64
64
65
- public async execute({ name }: z .infer <typeof parameters >) {
65
+ public async execute({ name }: z .infer <ZodObject < typeof this . parameters > >) {
66
66
return {
67
67
content: [
68
68
{
Original file line number Diff line number Diff line change 1
1
import { McpServer , type McpTool } from 'simple-mcp' ;
2
- import { z } from 'zod' ;
2
+ import { z , ZodObject } from 'zod' ;
3
3
4
- const parameters = z . object ( {
4
+ const parameters = {
5
5
name : z . string ( ) . describe ( 'The name is required' ) ,
6
- } ) ;
6
+ } ;
7
7
8
8
/**
9
9
* GreetTool class implements the McpTool interface
10
10
* This demonstrates how to create an MCP tool using a class-based approach
11
11
*/
12
- class GreetTool implements McpTool < typeof parameters . shape > {
12
+ class GreetTool implements McpTool < typeof parameters > {
13
13
// Tool name
14
14
public readonly name = 'greet' ;
15
15
16
16
// Define parameters with Zod schema
17
- public readonly parameters = parameters . shape ;
17
+ public readonly parameters = parameters ;
18
18
19
19
/**
20
20
* Execute method that will be called when the tool is invoked
21
21
* @param request The validated request parameters
22
22
*/
23
- public async execute ( { name } : z . infer < typeof parameters > ) {
23
+ public async execute ( { name } : z . infer < ZodObject < typeof this . parameters > > ) {
24
24
return {
25
25
content : [
26
26
{
You can’t perform that action at this time.
0 commit comments