Skip to content

Commit 3f53ba3

Browse files
committed
Extract shared MCP types and fix merge issue with test
1 parent 614a75b commit 3f53ba3

File tree

4 files changed

+46
-79
lines changed

4 files changed

+46
-79
lines changed

internal/api/mcp.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package api
2+
3+
import "github.com/mark3labs/mcp-go/mcp"
4+
5+
// methodNotFoundMessage is the error message returned by MCP servers when a method is not implemented.
6+
// TODO: This string matching is fragile and should be replaced with proper JSON-RPC error code checking.
7+
// Once mcp-go preserves JSON-RPC error codes, use errors.Is(err, mcp.ErrMethodNotFound) instead.
8+
// See: https://github.com/mark3labs/mcp-go/issues/593
9+
const methodNotFoundMessage = "Method not found"
10+
11+
// DomainMeta wraps mcp.Meta for API conversion.
12+
type DomainMeta mcp.Meta
13+
14+
// Meta represents metadata in API responses.
15+
type Meta map[string]any
16+
17+
// ToAPIType converts a domain meta to an API meta type.
18+
// This creates a flat _meta object structure as defined by the MCP specification.
19+
// Returns empty Meta{} if domain type is nil.
20+
// See: https://modelcontextprotocol.io/specification/2025-06-18/basic/index#meta
21+
func (d DomainMeta) ToAPIType() (Meta, error) {
22+
if (*mcp.Meta)(&d) == nil {
23+
return Meta{}, nil
24+
}
25+
26+
// The _meta field is MCP's reserved extensibility mechanism that allows both:
27+
// - progressToken: for out-of-band progress notifications (defined by spec)
28+
// - Additional fields: custom metadata from servers/clients (extensible)
29+
// Both types of fields are merged at the same level in the resulting map.
30+
result := make(Meta)
31+
32+
// Add progressToken if present (using MCP spec-defined field name).
33+
if d.ProgressToken != nil {
34+
result["progressToken"] = d.ProgressToken
35+
}
36+
37+
// Merge additional fields at the same level.
38+
for k, v := range d.AdditionalFields {
39+
result[k] = v
40+
}
41+
42+
return result, nil
43+
}

internal/api/prompts.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import (
1313
"github.com/mozilla-ai/mcpd/v2/internal/errors"
1414
)
1515

16-
// TODO: Remove this const once mcp-go preserves JSON-RPC error codes.
17-
// See: https://github.com/mark3labs/mcp-go/issues/593
18-
const methodNotFoundMessage = "Method not found"
19-
2016
// DomainPrompt wraps mcp.Prompt for API conversion.
2117
type DomainPrompt mcp.Prompt
2218

@@ -26,12 +22,6 @@ type DomainPromptArgument mcp.PromptArgument
2622
// DomainPromptMessage wraps mcp.PromptMessage for API conversion.
2723
type DomainPromptMessage mcp.PromptMessage
2824

29-
// DomainMeta wraps mcp.Meta for API conversion.
30-
type DomainMeta mcp.Meta
31-
32-
// Meta represents metadata in API responses.
33-
type Meta map[string]any
34-
3525
// Prompts represents a collection of Prompt types.
3626
type Prompts struct {
3727
Prompts []Prompt `json:"prompts"`
@@ -108,34 +98,6 @@ type GeneratePromptResponse struct {
10898
}
10999
}
110100

111-
// ToAPIType converts a domain meta to an API meta type.
112-
// This creates a flat _meta object structure as defined by the MCP specification.
113-
// Returns empty Meta{} if domain type is nil.
114-
// See: https://modelcontextprotocol.io/specification/2025-06-18/basic/index#meta
115-
func (d DomainMeta) ToAPIType() (Meta, error) {
116-
if (*mcp.Meta)(&d) == nil {
117-
return Meta{}, nil
118-
}
119-
120-
// The _meta field is MCP's reserved extensibility mechanism that allows both:
121-
// - progressToken: for out-of-band progress notifications (defined by spec)
122-
// - Additional fields: custom metadata from servers/clients (extensible)
123-
// Both types of fields are merged at the same level in the resulting map.
124-
result := make(Meta)
125-
126-
// Add progressToken if present (using MCP spec-defined field name).
127-
if d.ProgressToken != nil {
128-
result["progressToken"] = d.ProgressToken
129-
}
130-
131-
// Merge additional fields at the same level.
132-
for k, v := range d.AdditionalFields {
133-
result[k] = v
134-
}
135-
136-
return result, nil
137-
}
138-
139101
// ToAPIType converts a domain prompt to an API prompt.
140102
func (d DomainPrompt) ToAPIType() (Prompt, error) {
141103
var meta Meta

internal/api/resources.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,12 @@ import (
1313
"github.com/mozilla-ai/mcpd/v2/internal/errors"
1414
)
1515

16-
// TODO: Remove this const once mcp-go preserves JSON-RPC error codes.
17-
// See: https://github.com/mark3labs/mcp-go/issues/593
18-
const methodNotFoundMessage = "Method not found"
19-
2016
// DomainResource wraps mcp.Resource for API conversion.
2117
type DomainResource mcp.Resource
2218

2319
// DomainResourceTemplate wraps mcp.ResourceTemplate for API conversion.
2420
type DomainResourceTemplate mcp.ResourceTemplate
2521

26-
// DomainMeta wraps mcp.Meta for API conversion.
27-
type DomainMeta mcp.Meta
28-
29-
// Meta represents metadata in API responses.
30-
type Meta map[string]any
31-
3222
// Resources represents a collection of Resource types.
3323
type Resources struct {
3424
Resources []Resource `json:"resources"`
@@ -128,34 +118,6 @@ type ResourceContentResponse struct {
128118
Body []ResourceContent
129119
}
130120

131-
// ToAPIType converts a domain meta to an API meta type.
132-
// This creates a flat _meta object structure as defined by the MCP specification.
133-
// Returns empty Meta{} if domain type is nil.
134-
// See: https://modelcontextprotocol.io/specification/2025-06-18/basic/index#meta
135-
func (d DomainMeta) ToAPIType() (Meta, error) {
136-
if (*mcp.Meta)(&d) == nil {
137-
return Meta{}, nil
138-
}
139-
140-
// The _meta field is MCP's reserved extensibility mechanism that allows both:
141-
// - progressToken: for out-of-band progress notifications (defined by spec)
142-
// - Additional fields: custom metadata from servers/clients (extensible)
143-
// Both types of fields are merged at the same level in the resulting map.
144-
result := make(Meta)
145-
146-
// Add progressToken if present (using MCP spec-defined field name).
147-
if d.ProgressToken != nil {
148-
result["progressToken"] = d.ProgressToken
149-
}
150-
151-
// Merge additional fields at the same level.
152-
for k, v := range d.AdditionalFields {
153-
result[k] = v
154-
}
155-
156-
return result, nil
157-
}
158-
159121
// ToAPIType converts a domain resource to an API resource.
160122
func (d DomainResource) ToAPIType() (Resource, error) {
161123
var meta Meta

internal/daemon/api_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ func TestMapError(t *testing.T) {
339339
expectedStatus: 502,
340340
},
341341
{
342-
<<<<<<< HEAD
343342
name: "ErrPromptNotFound maps to 404",
344343
err: errors.ErrPromptNotFound,
345344
expectedStatus: 404,
@@ -362,7 +361,9 @@ func TestMapError(t *testing.T) {
362361
{
363362
name: "ErrPromptsNotImplemented maps to 501",
364363
err: errors.ErrPromptsNotImplemented,
365-
=======
364+
expectedStatus: 501,
365+
},
366+
{
366367
name: "ErrResourceNotFound maps to 404",
367368
err: errors.ErrResourceNotFound,
368369
expectedStatus: 404,
@@ -390,7 +391,6 @@ func TestMapError(t *testing.T) {
390391
{
391392
name: "ErrResourcesNotImplemented maps to 501",
392393
err: errors.ErrResourcesNotImplemented,
393-
>>>>>>> 7854d9b (Map resource domain errors to HTTP status codes)
394394
expectedStatus: 501,
395395
},
396396
{

0 commit comments

Comments
 (0)