55 "net/http"
66 "testing"
77
8- "github.com/mark3labs/mcp-go /mcp"
8+ "github.com/modelcontextprotocol/go-sdk /mcp"
99 "github.com/stretchr/testify/assert"
1010 "github.com/stretchr/testify/require"
1111)
@@ -110,56 +110,66 @@ func mockResponse(t *testing.T, code int, body interface{}) http.HandlerFunc {
110110
111111// createMCPRequest is a helper function to create a MCP request with the given arguments.
112112func createMCPRequest (args any ) mcp.CallToolRequest {
113+ // convert args to map[string]interface{} and serialize to JSON
114+ argsMap , ok := args .(map [string ]interface {})
115+ if ! ok {
116+ argsMap = make (map [string ]interface {})
117+ }
118+
119+ argsJSON , err := json .Marshal (argsMap )
120+ require .NoError (nil , err )
121+
122+ jsonRawMessage := json .RawMessage (argsJSON )
123+
113124 return mcp.CallToolRequest {
114- Params : struct {
115- Name string `json:"name"`
116- Arguments any `json:"arguments,omitempty"`
117- Meta * mcp.Meta `json:"_meta,omitempty"`
118- }{
119- Arguments : args ,
125+ Params : & mcp.CallToolParamsRaw {
126+ Arguments : jsonRawMessage ,
120127 },
121128 }
122129}
123130
124131// getTextResult is a helper function that returns a text result from a tool call.
125- func getTextResult (t * testing.T , result * mcp.CallToolResult ) mcp.TextContent {
132+ func getTextResult (t * testing.T , result * mcp.CallToolResult ) * mcp.TextContent {
126133 t .Helper ()
127134 assert .NotNil (t , result )
128135 require .Len (t , result .Content , 1 )
129136 require .IsType (t , mcp.TextContent {}, result .Content [0 ])
130- textContent := result .Content [0 ].(mcp.TextContent )
131- assert .Equal (t , "text" , textContent .Type )
137+ textContent := result .Content [0 ].(* mcp.TextContent )
132138 return textContent
133139}
134140
135- func getErrorResult (t * testing.T , result * mcp.CallToolResult ) mcp.TextContent {
141+ func getErrorResult (t * testing.T , result * mcp.CallToolResult ) * mcp.TextContent {
136142 res := getTextResult (t , result )
137143 require .True (t , result .IsError , "expected tool call result to be an error" )
138144 return res
139145}
140146
141147// getTextResourceResult is a helper function that returns a text result from a tool call.
142- func getTextResourceResult (t * testing.T , result * mcp.CallToolResult ) mcp.TextResourceContents {
148+ func getTextResourceResult (t * testing.T , result * mcp.CallToolResult ) * mcp.ResourceContents {
143149 t .Helper ()
144150 assert .NotNil (t , result )
145151 require .Len (t , result .Content , 2 )
146152 content := result .Content [1 ]
147153 require .IsType (t , mcp.EmbeddedResource {}, content )
148- resource := content .(mcp.EmbeddedResource )
149- require .IsType (t , mcp.TextResourceContents {}, resource .Resource )
150- return resource .Resource .(mcp.TextResourceContents )
154+ resource := content .(* mcp.EmbeddedResource )
155+
156+ require .IsType (t , mcp.ResourceContents {}, resource .Resource )
157+ require .NotEmpty (t , resource .Resource .Text )
158+ return resource .Resource
151159}
152160
153161// getBlobResourceResult is a helper function that returns a blob result from a tool call.
154- func getBlobResourceResult (t * testing.T , result * mcp.CallToolResult ) mcp.BlobResourceContents {
162+ func getBlobResourceResult (t * testing.T , result * mcp.CallToolResult ) * mcp.ResourceContents {
155163 t .Helper ()
156164 assert .NotNil (t , result )
157165 require .Len (t , result .Content , 2 )
158166 content := result .Content [1 ]
159167 require .IsType (t , mcp.EmbeddedResource {}, content )
160- resource := content .(mcp.EmbeddedResource )
161- require .IsType (t , mcp.BlobResourceContents {}, resource .Resource )
162- return resource .Resource .(mcp.BlobResourceContents )
168+
169+ resource := content .(* mcp.EmbeddedResource )
170+ require .IsType (t , mcp.ResourceContents {}, resource .Resource )
171+ require .NotEmpty (t , resource .Resource .Blob )
172+ return resource .Resource
163173}
164174
165175func TestOptionalParamOK (t * testing.T ) {
@@ -226,11 +236,9 @@ func TestOptionalParamOK(t *testing.T) {
226236
227237 for _ , tc := range tests {
228238 t .Run (tc .name , func (t * testing.T ) {
229- request := createMCPRequest (tc .args )
230-
231239 // Test with string type assertion
232240 if _ , isString := tc .expectedVal .(string ); isString || tc .errorMsg == "parameter myParam is not of type string, is bool" {
233- val , ok , err := OptionalParamOK [string ]( request , tc .paramName )
241+ val , ok , err := OptionalParamOK [string , map [ string ] any ]( tc . args , tc .paramName )
234242 if tc .expectError {
235243 require .Error (t , err )
236244 assert .Contains (t , err .Error (), tc .errorMsg )
@@ -245,7 +253,7 @@ func TestOptionalParamOK(t *testing.T) {
245253
246254 // Test with bool type assertion
247255 if _ , isBool := tc .expectedVal .(bool ); isBool || tc .errorMsg == "parameter myParam is not of type bool, is string" {
248- val , ok , err := OptionalParamOK [bool ]( request , tc .paramName )
256+ val , ok , err := OptionalParamOK [bool , map [ string ] any ]( tc . args , tc .paramName )
249257 if tc .expectError {
250258 require .Error (t , err )
251259 assert .Contains (t , err .Error (), tc .errorMsg )
@@ -260,7 +268,7 @@ func TestOptionalParamOK(t *testing.T) {
260268
261269 // Test with float64 type assertion (for number case)
262270 if _ , isFloat := tc .expectedVal .(float64 ); isFloat {
263- val , ok , err := OptionalParamOK [float64 ]( request , tc .paramName )
271+ val , ok , err := OptionalParamOK [float64 , map [ string ] any ]( tc . args , tc .paramName )
264272 if tc .expectError {
265273 // This case shouldn't happen for float64 in the defined tests
266274 require .Fail (t , "Unexpected error case for float64" )
0 commit comments