Skip to content

Commit 67a4793

Browse files
tommaso-moromattdholloway
authored andcommitted
PoC full flow (hello world example)
1 parent 1820a0f commit 67a4793

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

internal/ghmcp/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ func NewMCPServer(cfg MCPServerConfig) (*mcp.Server, error) {
250250
// enable toolsets or tools explicitly that do need registration).
251251
inventory.RegisterAll(context.Background(), ghServer, deps)
252252

253+
// Register MCP App UI resources (static resources for tool UI)
254+
github.RegisterUIResources(ghServer)
255+
253256
// Register dynamic toolset management tools (enable/disable) - these are separate
254257
// meta-tools that control the inventory, not part of the inventory itself
255258
if cfg.DynamicToolsets {

pkg/github/context_tools.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@ import (
1515
"github.com/shurcooL/githubv4"
1616
)
1717

18+
// GetMeUIResourceURI is the URI for the get_me tool's MCP App UI resource.
19+
const GetMeUIResourceURI = "ui://github-mcp-server/get-me"
20+
21+
// GetMeUIHTML is the HTML content for the get_me tool's MCP App UI.
22+
// This is a simple "Hello World" demo with bold red text.
23+
const GetMeUIHTML = `<!DOCTYPE html>
24+
<html lang="en">
25+
<head>
26+
<meta charset="UTF-8">
27+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
28+
<title>GitHub MCP Server - Get Me</title>
29+
<style>
30+
body {
31+
font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
32+
padding: 20px;
33+
margin: 0;
34+
background: var(--color-background-primary, #fff);
35+
color: var(--color-text-primary, #333);
36+
}
37+
.hello-world {
38+
font-weight: bold;
39+
color: red;
40+
font-size: 1.5em;
41+
}
42+
</style>
43+
</head>
44+
<body>
45+
<p class="hello-world">Hello World</p>
46+
</body>
47+
</html>`
48+
1849
// UserDetails contains additional fields about a GitHub user not already
1950
// present in MinimalUser. Used by get_me context tool but omitted from search_users.
2051
type UserDetails struct {
@@ -51,6 +82,12 @@ func GetMe(t translations.TranslationHelperFunc) inventory.ServerTool {
5182
// Use json.RawMessage to ensure "properties" is included even when empty.
5283
// OpenAI strict mode requires the properties field to be present.
5384
InputSchema: json.RawMessage(`{"type":"object","properties":{}}`),
85+
// MCP Apps UI metadata - links this tool to its UI resource
86+
Meta: mcp.Meta{
87+
"ui": map[string]any{
88+
"resourceUri": GetMeUIResourceURI,
89+
},
90+
},
5491
},
5592
nil,
5693
func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, _ map[string]any) (*mcp.CallToolResult, any, error) {

pkg/github/ui_resources.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package github
2+
3+
import (
4+
"context"
5+
6+
"github.com/modelcontextprotocol/go-sdk/mcp"
7+
)
8+
9+
// RegisterUIResources registers MCP App UI resources with the server.
10+
// These are static resources (not templates) that serve HTML content for
11+
// MCP App-enabled tools.
12+
func RegisterUIResources(s *mcp.Server) {
13+
// Register the get_me UI resource
14+
s.AddResource(
15+
&mcp.Resource{
16+
URI: GetMeUIResourceURI,
17+
Name: "get_me_ui",
18+
Description: "MCP App UI for the get_me tool",
19+
MIMEType: "text/html",
20+
},
21+
func(_ context.Context, _ *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
22+
return &mcp.ReadResourceResult{
23+
Contents: []*mcp.ResourceContents{
24+
{
25+
URI: GetMeUIResourceURI,
26+
MIMEType: "text/html",
27+
Text: GetMeUIHTML,
28+
},
29+
},
30+
}, nil
31+
},
32+
)
33+
}

0 commit comments

Comments
 (0)