Skip to content

Conversation

jclyne
Copy link
Contributor

@jclyne jclyne commented Sep 25, 2025

Motivation and Context

The schema for the InitializeResult contains an optional 'instructions' string

How Has This Been Tested?

Its relatively simple change with unit tests included

Breaking Changes

No, field is optional and defaults to null

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

The instructions string is included in the schema for for version "2025-03-26"

The instructions in the Server class are given as a provider function with the result of the provider propagated to the underlying ServerSession. As the ServerSession change is meant to allow for a 'Singleton scoped' server class, this provides the ability to dynamically modify the instructions at the server level but have them be immutable per session.

This also refactors the serverInfo and instructions properties to be protected. This Server class is open and meant to be overridden, there is no harm in having these immutable properties available to subclasses.

This adds the serverInstructions to the client as returned from the InitializeResult. This is used to verify the response in the Server tests.

@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 15:15
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements the optional instructions field from the MCP schema version "2025-03-26" by adding it to the Server constructor and propagating it through to the InitializeResult.

  • Added instructions parameter to Server constructor with default value of null
  • Updated InitializeResult data class to include optional instructions field
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
kotlin-sdk-core/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/types.kt Added instructions field to InitializeResult data class with documentation
kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/Server.kt Updated Server constructor to accept instructions parameter and pass it to InitializeResult
kotlin-sdk-core/src/commonTest/kotlin/io/modelcontextprotocol/kotlin/sdk/TypesTest.kt Added comprehensive tests for InitializeResult with and without instructions
kotlin-sdk-test/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/ServerTest.kt Added tests for Server constructor with instructions parameter variants
kotlin-sdk-core/api/kotlin-sdk-core.api Updated API signatures to reflect new InitializeResult structure
kotlin-sdk-server/api/kotlin-sdk-server.api Updated API signatures to reflect new Server constructor

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jclyne jclyne requested a review from Copilot September 25, 2025 15:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@kpavlov kpavlov force-pushed the support-for-mcp-server-instructions branch from 0d8253e to 6a95a59 Compare September 28, 2025 03:36
Copy link
Contributor

@kpavlov kpavlov left a comment

Choose a reason for hiding this comment

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

Thank you @jclyne
I have one question about testing, but overall looks good to me

}

@Test
fun `Server constructor should accept instructions parameter`() = runTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the test!
One question: Is it possible to verify in the test that the server has received the instructions string?
Also, the test could be parametrized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The serverInstructions were added to the client as a property that can be verified in these tests.

Comment on lines +434 to +435
val json = McpJson.encodeToString(result)
val decoded = McpJson.decodeFromString<InitializeResult>(json)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we should introduce some serialization helper for tests like this, like here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would probably be applicable to all the tests in this file, so I would prefer to leave it to a different PR if that's ok

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with both statements

@kpavlov kpavlov added enhancement New feature or request question Further information is requested labels Sep 28, 2025
…ons' into support-for-mcp-server-instructions
# Conflicts:
#	kotlin-sdk-server/api/kotlin-sdk-server.api
#	kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/Server.kt
…ation to the ServerTests (addresses PR feedback)
…sourced dynamically for each session if desired
@jclyne jclyne requested a review from Copilot September 29, 2025 18:42
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jclyne jclyne requested a review from Copilot September 29, 2025 18:56
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@jclyne jclyne requested a review from kpavlov September 29, 2025 21:09
kpavlov
kpavlov previously approved these changes Sep 29, 2025
Copy link
Contributor

@kpavlov kpavlov left a comment

Choose a reason for hiding this comment

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

LGTM

@kpavlov kpavlov requested a review from devcrocod September 29, 2025 21:28
@kyeotic
Copy link

kyeotic commented Sep 30, 2025

@kpavlov We also need this for parity with FastMCP python servers. Any chance you can ballpark an ETA for this getting merged/released?

Copy link
Contributor

@devcrocod devcrocod left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

I have a question regarding the api design, could you please take a look?
Everything else looks good to me!

public open class Server(
protected val serverInfo: Implementation,
protected val options: ServerOptions,
protected val instructionsProvider: (() -> String)? = null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this implemented as a lambda and not just a string?

Copy link
Contributor Author

@jclyne jclyne Oct 2, 2025

Choose a reason for hiding this comment

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

This is allowing the instructions to potentially be dynamically loaded from a database or string server. With the change to the ServerSession, the Server seems to take more of a Singleton scope vs a Server per stream. The idea is that the Server has a provider method for the string which it evaluates as a string value for the ServerSession.

Its possible to add an additional constructor that just takes a static string and converts it to a lamda, but that is trivial for the caller.

I went ahead and added an alternative constructor that takes a static string

@devcrocod
Copy link
Contributor

Hi @jclyne
We recently added ServerSession, which still requires some improvements.
Soon we plan to estimate the timeline for a stable release.

In the meantime, next week we’d like to set up snapshot releases

@jclyne
Copy link
Contributor Author

jclyne commented Oct 2, 2025

Hi @jclyne We recently added ServerSession, which still requires some improvements. Soon we plan to estimate the timeline for a stable release.

In the meantime, next week we’d like to set up snapshot releases

Thanks @devcrocod! I would like to get this in the snapshot release if at all possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants