Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaef9456

Browse files
Implement working completion support with custom in-process client
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent6dec5da commitaef9456

File tree

3 files changed

+80
-19
lines changed

3 files changed

+80
-19
lines changed

‎pkg/github/completion_integration_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/google/go-github/v69/github"
8-
"github.com/mark3labs/mcp-go/client"
98
"github.com/mark3labs/mcp-go/mcp"
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
@@ -23,8 +22,8 @@ func TestGitHubMCPServerCompletionIntegration(t *testing.T) {
2322
ghServer:=NewGitHubServer("test",getClient)
2423
require.NotNil(t,ghServer)
2524

26-
// Create an in-process client
27-
mcpClient,err:=client.NewInProcessClient(ghServer.GetMCPServer())
25+
// Create an in-process client with our custom GitHubMCPServer transport
26+
mcpClient,err:=NewInProcessClientWithGitHubServer(ghServer)
2827
require.NoError(t,err)
2928

3029
// Initialize the client
@@ -118,8 +117,8 @@ func TestGitHubMCPServerCompletionCapabilities(t *testing.T) {
118117
ghServer:=NewGitHubServer("test",getClient)
119118
require.NotNil(t,ghServer)
120119

121-
// Create an in-process client
122-
mcpClient,err:=client.NewInProcessClient(ghServer.GetMCPServer())
120+
// Create an in-process client with our custom GitHubMCPServer transport
121+
mcpClient,err:=NewInProcessClientWithGitHubServer(ghServer)
123122
require.NoError(t,err)
124123

125124
// Initialize the client

‎pkg/github/github_inprocess_client.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package github
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
8+
"github.com/mark3labs/mcp-go/client"
9+
"github.com/mark3labs/mcp-go/client/transport"
10+
"github.com/mark3labs/mcp-go/mcp"
11+
)
12+
13+
// GitHubInProcessTransport creates an in-process transport that uses our GitHubMCPServer
14+
// This ensures that completion requests go through our HandleMessage override
15+
typeGitHubInProcessTransportstruct {
16+
server*GitHubMCPServer
17+
notificationHandlerfunc(mcp.JSONRPCNotification)
18+
}
19+
20+
// NewGitHubInProcessTransport creates a new in-process transport for GitHubMCPServer
21+
funcNewGitHubInProcessTransport(server*GitHubMCPServer)*GitHubInProcessTransport {
22+
return&GitHubInProcessTransport{
23+
server:server,
24+
}
25+
}
26+
27+
func (c*GitHubInProcessTransport)Start(ctx context.Context)error {
28+
returnnil
29+
}
30+
31+
func (c*GitHubInProcessTransport)SendRequest(ctx context.Context,request transport.JSONRPCRequest) (*transport.JSONRPCResponse,error) {
32+
requestBytes,err:=json.Marshal(request)
33+
iferr!=nil {
34+
returnnil,fmt.Errorf("failed to marshal request: %w",err)
35+
}
36+
requestBytes=append(requestBytes,'\n')
37+
38+
// This is the key part: call HandleMessage on our GitHubMCPServer
39+
// which will route completion requests to our handler
40+
respMessage:=c.server.HandleMessage(ctx,requestBytes)
41+
respByte,err:=json.Marshal(respMessage)
42+
iferr!=nil {
43+
returnnil,fmt.Errorf("failed to marshal response message: %w",err)
44+
}
45+
rpcResp:= transport.JSONRPCResponse{}
46+
err=json.Unmarshal(respByte,&rpcResp)
47+
iferr!=nil {
48+
returnnil,fmt.Errorf("failed to unmarshal response message: %w",err)
49+
}
50+
51+
return&rpcResp,nil
52+
}
53+
54+
func (c*GitHubInProcessTransport)SendNotification(ctx context.Context,notification mcp.JSONRPCNotification)error {
55+
// For in-process transport, we can just forward notifications to the handler
56+
ifc.notificationHandler!=nil {
57+
c.notificationHandler(notification)
58+
}
59+
returnnil
60+
}
61+
62+
func (c*GitHubInProcessTransport)SetNotificationHandler(handlerfunc(mcp.JSONRPCNotification)) {
63+
c.notificationHandler=handler
64+
}
65+
66+
func (c*GitHubInProcessTransport)Close()error {
67+
returnnil
68+
}
69+
70+
// NewInProcessClientWithGitHubServer creates a client that works with GitHubMCPServer
71+
funcNewInProcessClientWithGitHubServer(server*GitHubMCPServer) (*client.Client,error) {
72+
ghTransport:=NewGitHubInProcessTransport(server)
73+
returnclient.NewClient(ghTransport),nil
74+
}

‎pkg/github/server.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,9 @@ func (s *GitHubMCPServer) handleCompletion(ctx context.Context, id any, message
9696

9797
// Helper functions for JSON-RPC responses
9898
funccreateErrorResponse(idany,codeint,messagestring) mcp.JSONRPCMessage {
99-
// Convert id to RequestId type
100-
varrequestId mcp.RequestId
101-
ifid!=nil {
102-
requestId=id.(mcp.RequestId)
103-
}
104-
10599
return mcp.JSONRPCError{
106100
JSONRPC:mcp.JSONRPC_VERSION,
107-
ID:requestId,
101+
ID:mcp.NewRequestId(id),
108102
Error:struct {
109103
Codeint`json:"code"`
110104
Messagestring`json:"message"`
@@ -117,15 +111,9 @@ func createErrorResponse(id any, code int, message string) mcp.JSONRPCMessage {
117111
}
118112

119113
funccreateResponse(idany,resultany) mcp.JSONRPCMessage {
120-
// Convert id to RequestId type
121-
varrequestId mcp.RequestId
122-
ifid!=nil {
123-
requestId=id.(mcp.RequestId)
124-
}
125-
126114
return mcp.JSONRPCResponse{
127115
JSONRPC:mcp.JSONRPC_VERSION,
128-
ID:requestId,
116+
ID:mcp.NewRequestId(id),
129117
Result:result,
130118
}
131119
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp