Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add completion and resource template support #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gavinaboulhosn
Copy link

@gavinaboulhosn gavinaboulhosn commented Dec 12, 2024

  • Add support for MCP completions
  • Implement URI templates for dynamic resources
  • Add completion handlers for prompts and resources
  • Update documentation with new features and examples

This implementation follows the MCP specification for completions and resource templates

References:
https://spec.modelcontextprotocol.io/specification/server/resources/#resource-templates
https://spec.modelcontextprotocol.io/specification/server/utilities/completion/

- Add support for MCP completions
- Implement URI templates for dynamic resources
- Add completion handlers for prompts and resources
- Update documentation with new features and examples

This implementation follows the MCP specification for completions and
resource templates while maintaining backwards compatibility.
@gavinaboulhosn
Copy link
Author

Following the initial implementation, I'm adding these type safety improvements

  • better type inference for completion arguments:
    async complete?<K extends keyof TArgs>(
      argumentName: K,
      value: z.infer<TArgs[K]["type"]>
    ): Promise<PromptCompletion>;
    This ensures that completion values match their argument's schema type.

For example, with this improvement:

interface GreetingInput {
  language: z.ZodString;
  count: z.ZodNumber;
}

TypeScript will properly type value based on the argument - string for "language", number for "count".

@gavinaboulhosn gavinaboulhosn marked this pull request as draft December 13, 2024 01:45
Gavin Aboulhosn added 2 commits December 13, 2024 11:16
Improve type safety for completions in both prompts and resources:
- Add generic type parameters to PromptProtocol and ResourceProtocol
- Add type-safe argument completion methods with proper inference
- Update MCPServer to handle typed protocols
- Add schema validation in completion methods

This ensures completion arguments and values maintain proper typing
throughout the completion flow.
@gavinaboulhosn gavinaboulhosn marked this pull request as ready for review December 13, 2024 16:21
@QuantGeekDev QuantGeekDev self-requested a review December 13, 2024 16:50
@QuantGeekDev
Copy link
Owner

This looks sweet, thanks for your contribution @gavinaboulhosn - I'll try to review this over the following 24 hours
Are you part of our discord server? Join our community: https://www.reddit.com/r/modelcontextprotocol/comments/1h16cjd/discord_server/

@gavinaboulhosn
Copy link
Author

I'm going to tests this a little more. There isn't support for completions in tools like MCP inspector so I'm working on potentially opening a PR there to help me verify these changes.

@QuantGeekDev
Copy link
Owner

I'm going to tests this a little more. There isn't support for completions in tools like MCP inspector so I'm working on potentially opening a PR there to help me verify these changes.

Got it - sorry I haven't been able to get to this yet. How can I verify that this works? What's your email / discord? I'd love to connect and chat thru these changes and see how I can help. Would love to add more features to mcp inspector too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants