-
Notifications
You must be signed in to change notification settings - Fork 712
Closed
Description
Problem Statement
Currently, MCP allows registering session-specific tools and static resources using SessionWithTools and SessionWithResources.
However, there’s no equivalent support for resource templates, and attempts to add one fail due to URI validation in AddSessionResources, resulting in: invalid resource URI:
Proposed Solution
Introduce support for session-specific resource templates, e.g. SessionWithResourceTemplates, analogous to the existing SessionWithTools and SessionWithResources.
This would allow handlers that define ResourceTemplates visible only within a single session.
Example Usage
// Add a session resource template
newResourceTemplate := mcp.NewResourceTemplate(
resourceURI,
resourceName,
mcp.WithTemplateDescription(resourceDescription),
mcp.WithTemplateMIMEType(resourceMIMEType),
)
err := s.AddSessionResourceTemplate(
sessionID,
newResourceTemplate,
func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
// This handler is only available to this specific session
return []mcp.ResourceContents{
mcp.TextResourceContents{
URI: request.Params.URI,
MIMEType: "application/json",
Text: "Example result text",
},
}, nil
},
)
if err != nil {
log.Printf("Failed to add session resource template: %v", err)
}Rationale / Benefits
- Enables session-scoped resource templates (parity with tools/resources).
- Simplifies dynamic per-session configuration of resource templates.
- Avoids URI validation errors for session-bound contexts.
Metadata
Metadata
Assignees
Labels
No labels