Skip to content

Update mcp functions to use ServerSSESession with lambda receiver #180

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

devcrocod
Copy link
Contributor

Provide ServeSSESession as a context receiver.

Motivation and Context

How Has This Been Tested?

locally

Breaking Changes

Yes, changed signature for mcp server extensions

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

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 updates the MCP (Model Context Protocol) server functions to provide ServerSSESession as a context receiver instead of using a simple lambda. This change allows the lambda functions to access ServerSSESession properties and methods directly within their scope.

Key changes:

  • Updated function signatures to use ServerSSESession.() -> Server instead of () -> Server
  • Applied changes to all mcp() functions and the deprecated MCP() function
  • Updated the internal mcpSseEndpoint function parameter accordingly

Reviewed Changes

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

File Description
KtorServer.kt Updated all mcp function signatures to use ServerSSESession as context receiver
kotlin-sdk.api Updated API signatures from Function0 to Function1 to reflect the context receiver change
Comments suppressed due to low confidence (1)

src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/KtorServer.kt:74

  • The function call block() is incorrect. Since the block parameter now has a ServerSSESession receiver, it should be called as block(this) or this.block() to provide the ServerSSESession context.
    val server = block()

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.

1 participant