Skip to content

Add instructions support to MCP::Server #87

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

koic
Copy link
Member

@koic koic commented Jul 23, 2025

Motivation and Context

The response of the init method can include instructions. https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle

instructions appear to be supported starting from the 2025-03-26 specification.

If instructions is used with an unsupported protocol version, an ArgumentError will be raised.

How Has This Been Tested?

Existing tests have been updated and new tests have been added.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

As additional context, the TypeScript SDK also treats instructions as optional. https://github.com/modelcontextprotocol/typescript-sdk/blob/1.16.0/src/types.ts#L356-L361

The response of the `init` method can include `instructions`.
https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle

`instructions` appear to be supported starting from the 2025-03-26 specification.

- https://modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle (supports `instructions`)
- https://modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle (does not support `instructions`)

If `instructions` is used with an unsupported protocol version, an `ArgumentError` will be raised.

As additional context, the TypeScript SDK also treats `instructions` as optional.
https://github.com/modelcontextprotocol/typescript-sdk/blob/1.16.0/src/types.ts#L356-L361
if @configuration.protocol_version == "2024-11-05" && @instructions
message = "`instructions` supported by protocol version 2025-03-26 or higher"
raise ArgumentError, message
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If accepting the instructions parameter with the older "2024-11-05" protocol version is considered preferable, this logic could be removed as it only introduces unnecessary complexity.

Copy link
Contributor

@atesgoral atesgoral Aug 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case there are picky clients that could error on unexpected properties, I think being safe (backwards compatible) is good here.

But are we doing this kind of check uniformly for all features? Is there a Ruby-friendly annotation technique we could adopt to start doing this more declaratively...

I'm happy with this change as it is, though.

def index
server = MCP::Server.new(
name: "my_server",
version: "1.0.0",
instructions: "A simple MCP server with custom tools and prompts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://modelcontextprotocol.io/specification/2025-06-18/schema describes instructions as:

Instructions describing how to use the server and its features.

This can be used by clients to improve the LLM’s understanding of available tools, resources, etc. It can be thought of like a “hint” to the model. For example, this information MAY be added to the system prompt.

So, it's not meant as a "description" for the server that is intended for humans, but more of a "how to get the best out of me" hint intended for the LLM.

I'm having a hard time coming up with a good example.

Maybe something humourous like "Use this server wisely" or "Use the tools of this server as a last resort"... Just something sounding more like it's intended for the LLM.

Comment on lines 58 to +59
@configuration = MCP.configuration.merge(configuration)
if @configuration.protocol_version == "2024-11-05" && @instructions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stylistic subjective nitpick:

Suggested change
@configuration = MCP.configuration.merge(configuration)
if @configuration.protocol_version == "2024-11-05" && @instructions
@configuration = MCP.configuration.merge(configuration)
if @configuration.protocol_version == "2024-11-05" && @instructions

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