-
Notifications
You must be signed in to change notification settings - Fork 209
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Using mcp.StdioTransport{}
for the server transport protocol causes os.Stout
to be closed when the server is stopped which prevents go test code coverage from being reported:
$ go test -coverprofile cover.out ./...
error generating coverage report: write /dev/stdout: file already closed
To Reproduce
Create the following main and test files:
package main
import (
"context"
"time"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
RunServer()
}
func RunServer() {
impl := &mcp.Implementation{}
options := &mcp.ServerOptions{}
server := mcp.NewServer(impl, options)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
server.Run(ctx, &mcp.InMemoryTransport{})
}
package main
import "testing"
func Test_RunServer(t *testing.T) {
RunServer()
}
Then run the following to test the code:
$ go test -coverprofile cover.out ./...
Expected behavior
Coverage should be reported and the tests shouldn't fail
$ go test -coverprofile cover.out ./...
ok mcp-test 0.114s coverage: 87.5% of statements
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working