Skip to content

Commit 3ce9de9

Browse files
made more changes
1 parent d3c7eb5 commit 3ce9de9

5 files changed

Lines changed: 61 additions & 26 deletions

File tree

dgraph/cmd/alpha/run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ import (
4343
_ "github.com/dgraph-io/gqlparser/v2/validator/rules" // make gql validator init() all rules
4444
"github.com/dgraph-io/ristretto/v2/z"
4545
"github.com/hypermodeinc/dgraph/v25/audit"
46+
"github.com/hypermodeinc/dgraph/v25/dgraph/cmd/mcp"
4647
"github.com/hypermodeinc/dgraph/v25/edgraph"
4748
"github.com/hypermodeinc/dgraph/v25/graphql/admin"
48-
dgraphmcp "github.com/hypermodeinc/dgraph/v25/mcp"
4949
"github.com/hypermodeinc/dgraph/v25/posting"
5050
"github.com/hypermodeinc/dgraph/v25/schema"
5151
"github.com/hypermodeinc/dgraph/v25/tok"
@@ -113,7 +113,7 @@ they form a Raft group and provide synchronous replication.
113113
flag.String("custom_tokenizers", "",
114114
"Comma separated list of tokenizer plugins for custom indices.")
115115

116-
flag.Bool("mcp", true, "Enable MCP server.")
116+
flag.Bool("mcp", false, "run MCP server along with alpha.")
117117

118118
// By default Go GRPC traces all requests.
119119
grpc.EnableTracing = false
@@ -477,7 +477,7 @@ func serveGRPC(l net.Listener, tlsCfg *tls.Config, closer *z.Closer) {
477477
}
478478

479479
func setupMcp(baseMux *http.ServeMux, connectionString, url string, readOnly bool) error {
480-
s, err := dgraphmcp.NewMCPServer(connectionString, readOnly)
480+
s, err := mcp.NewMCPServer(connectionString, readOnly)
481481
if err != nil {
482482
glog.Errorf("Failed to initialize MCPServer: %v", err)
483483
return err

mcp/README.md renamed to dgraph/cmd/mcp/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ management and querying capabilities. There are two ways you can access the mcp
1919
- Install dgraph alpha
2020
- Start dgraph alpha
2121

22+
For Read only:
23+
24+
```json
25+
{
26+
"dgraph-mcp-ro": {
27+
"serverUrl": "http://localhost:8080/mcp-ro/sse"
28+
}
29+
}
30+
```
31+
32+
For Read write:
33+
2234
```json
2335
{
2436
"dgraph-mcp": {
@@ -29,26 +41,22 @@ management and querying capabilities. There are two ways you can access the mcp
2941

3042
## Setup Instructions for go code
3143

32-
- Install golang 1.23+
33-
- Clone the repository
34-
- cd mcp/dgraph-mcp
35-
- go build
44+
- Install dgraph binary
3645
- Insert the following to your mcp config:
3746

3847
```json
3948
{
4049
"mcpServers": {
4150
"dgraph": {
42-
"command": "<path to dgraph folder>/mcp/dgraph-mcp/dgraph-mcp",
43-
"env": {
44-
"DGRAPH_CONNECTION": "dgraph://<host>:443?sslmode=verify-ca&bearertoken=xxxxxxxxxx",
45-
"DGRAPH_READ_ONLY": "true" / "false",
46-
}
51+
"command": "dgraph_binary",
52+
"args": ["mcp -c dgraph://localhost:9080"]
4753
}
4854
}
4955
}
5056
```
5157

58+
- Modify the server details using args in dgraph mcp command
59+
5260
### Local Setup for Claude Desktop
5361

5462
You can setup a local experience using Claude app
Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package mcp
22

33
import (
44
"context"
5+
_ "embed"
56
"fmt"
7+
"sync"
68
"time"
79

810
"github.com/dgraph-io/dgo/v250"
@@ -13,16 +15,23 @@ import (
1315
"github.com/mark3labs/mcp-go/server"
1416
)
1517

18+
//go:embed prompt.txt
19+
var promptBytes []byte
20+
1621
var dgraphConnection *dgo.Dgraph
22+
var getConnLock sync.Mutex
1723

1824
func getConn(connectionString string) (*dgo.Dgraph, error) {
25+
getConnLock.Lock()
26+
defer getConnLock.Unlock()
27+
1928
if dgraphConnection != nil {
2029
return dgraphConnection, nil
2130
}
2231

2332
conn, err := dgo.Open(connectionString)
2433
if err != nil {
25-
for i := range 10 {
34+
for i := range 3 {
2635
time.Sleep(time.Second * time.Duration(i))
2736
conn, err = dgo.Open(connectionString)
2837
if err == nil {
@@ -41,7 +50,7 @@ func getConn(connectionString string) (*dgo.Dgraph, error) {
4150
func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, error) {
4251
s := server.NewMCPServer(
4352
"Dgraph MCP Server",
44-
"1.0.0",
53+
"v25.0.0",
4554
server.WithResourceCapabilities(true, true),
4655
server.WithLogging(),
4756
server.WithRecovery(),
@@ -226,10 +235,10 @@ func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, er
226235
{
227236
"shortest_path_query": "
228237
{
229-
q(func: eq(guid, "something") { // get first uid in form of a query
238+
q(func: eq(guid, "first guid") { // get first uid in form of a query
230239
a as uid
231240
}
232-
q1(func: eq(guid, "something else")) { // get second uid in form of a query
241+
q1(func: eq(guid, "second guid")) { // get second uid in form of a query
233242
b as uid
234243
}
235244
path as shortest(from: uid(a), to: uid(b), numpaths: 5, maxheapsize: 10000) {
@@ -259,10 +268,10 @@ func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, er
259268
{
260269
"shortest_path_query": "
261270
{
262-
q(func: eq(guid, "something") { // get first uid in form of a query
271+
q(func: eq(guid, "first guid")) { // get first uid in form of a query
263272
a as uid
264273
}
265-
q1(func: eq(guid, "something else")) { // get second uid in form of a query
274+
q1(func: eq(guid, "second guid")) { // get second uid in form of a query
266275
b as uid
267276
}
268277
@@ -302,5 +311,24 @@ func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, er
302311
}, nil
303312
})
304313

314+
addPrompt(s)
315+
305316
return s, nil
306317
}
318+
319+
func addPrompt(s *server.MCPServer) {
320+
prompt := string(promptBytes)
321+
s.AddPrompt(mcp.NewPrompt("Quick start prompt",
322+
mcp.WithPromptDescription("A quick Start prompt for new users and llms"),
323+
), func(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
324+
return mcp.NewGetPromptResult(
325+
"A quick start prompt",
326+
[]mcp.PromptMessage{
327+
mcp.NewPromptMessage(
328+
mcp.RoleAssistant,
329+
mcp.NewTextContent(prompt),
330+
),
331+
},
332+
), nil
333+
})
334+
}

dgraph/cmd/mcp/run.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/mark3labs/mcp-go/server"
1111
"github.com/spf13/cobra"
1212

13-
"github.com/hypermodeinc/dgraph/v25/mcp"
1413
"github.com/hypermodeinc/dgraph/v25/x"
1514
)
1615

@@ -23,28 +22,28 @@ func init() {
2322
Use: "mcp",
2423
Short: "Run Dgraph MCP server",
2524
Long: `
26-
A Dgraph MCP server is a long running process that provides an STDIO interface for running mcp
25+
A Dgraph MCP server is a long running process that provides an STDIO
26+
interface for running mcp server.
2727
`,
2828
Run: func(cmd *cobra.Command, args []string) {
29-
defer x.StartProfile(Mcp.Conf).Stop()
3029
run()
3130
},
32-
Annotations: map[string]string{"group": "core"},
31+
Annotations: map[string]string{"group": "tool"},
3332
}
3433
Mcp.EnvPrefix = "DGRAPH_MCP"
3534
Mcp.Cmd.SetHelpTemplate(x.NonRootTemplate)
3635

3736
flag := Mcp.Cmd.Flags()
3837

39-
flag.StringP("connection", "c", "dgraph://localhost:9080", "Dgraph connection string.")
38+
flag.StringP("con-str", "c", "", "Dgraph connection string.")
4039
flag.Bool("read-only", false, "Run MCP server in read-only mode.")
4140
}
4241

4342
func run() {
44-
connectionString := Mcp.Conf.GetString("connection")
45-
readOnly := Mcp.Conf.GetBool("read_only")
43+
connectionString := Mcp.Conf.GetString("con-str")
44+
readOnly := Mcp.Conf.GetBool("read-only")
4645

47-
s, err := mcp.NewMCPServer(connectionString, readOnly)
46+
s, err := NewMCPServer(connectionString, readOnly)
4847
if err != nil {
4948
glog.Errorf("Failed to initialize MCPServer: %v", err)
5049
return

0 commit comments

Comments
 (0)