Repository: dgraph-io/dgraph
File: dgraph/cmd/mcp/mcp_server.go (Go)

Code before:

var True = true
var False = false

// NewMCPServer initializes and returns a new MCPServer instance.
func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, error) {
	s := server.NewMCPServer(
		"Dgraph MCP Server",
		x.Version(),
		server.WithResourceCapabilities(true, true),
		server.WithLogging(),
		server.WithRecovery(),
	)

	schemaTool := mcp.NewTool("get_schema",
		mcp.WithDescription("Get Dgraph DQL Schema from dgraph db"),
		mcp.WithToolAnnotation(mcp.ToolAnnotation{
			ReadOnlyHint:    &True,
			DestructiveHint: &False,
			IdempotentHint:  &True,
			OpenWorldHint:   &False,
		}),
	)

	queryCheckTool := mcp.NewTool("check_query",
		mcp.WithDescription("Check if the Dgraph DQL Query is valid"),
		mcp.WithString("query",
			mcp.Required(),
			mcp.Description("The query to perform"),
		),
		mcp.WithString("variables",
			mcp.Description("The variables to be used in the query. Should be in json format to be unmarshalled into map[string]string"),
		),
		mcp.WithToolAnnotation(mcp.ToolAnnotation{
			ReadOnlyHint:    &True,
			DestructiveHint: &False,
			IdempotentHint:  &True,
			OpenWorldHint:   &False,
		}),
	)

	s.AddTool(queryCheckTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
		args := request.GetArguments()
		if args == nil {
			return mcp.NewToolResultError("Query must be present"), nil
		}
		queryArg, ok := args["query"]
		if !ok || queryArg == nil {
			return mcp.NewToolResultError("Query must be present"), nil
		}


Review comment (suggestion):
Maybe this should be more accurately named `check_query_syntax` or even better IMO `validate_query_syntax`

Code after:
	return conn, nil
}

var True = true
var False = false

// NewMCPServer initializes and returns a new MCPServer instance.
func NewMCPServer(connectionString string, readOnly bool) (*server.MCPServer, error) {
	s := server.NewMCPServer(
		"Dgraph MCP Server",
		x.Version(),
		server.WithResourceCapabilities(true, true),
		server.WithLogging(),
		server.WithRecovery(),
	)

	schemaTool := mcp.NewTool("get_schema",
		mcp.WithDescription("Get Dgraph DQL Schema from dgraph db"),
		mcp.WithToolAnnotation(mcp.ToolAnnotation{
			ReadOnlyHint:    &True,
			DestructiveHint: &False,
			IdempotentHint:  &True,
			OpenWorldHint:   &False,
		}),
	)

	validateQuerySyntaxTool := mcp.NewTool("validate_query_syntax",
		mcp.WithDescription("Check if a Dgraph DQL Query is valid"),
		mcp.WithString("query",
			mcp.Required(),
			mcp.Description("The query to validate"),
		),
		mcp.WithString("variables",
			mcp.Description("The variables to be used in the query. Should be in JSON format to be unmarshalled into map[string]string"),
		),
		mcp.WithToolAnnotation(mcp.ToolAnnotation{
			ReadOnlyHint:    &True,
			DestructiveHint: &False,
			IdempotentHint:  &True,
			OpenWorldHint:   &False,
		}),
	)

	s.AddTool(validateQuerySyntaxTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
		args := request.GetArguments()
		if args == nil {
			return mcp.NewToolResultError("Query must be present"), nil
		}
		queryArg, ok := args["query"]
		if !ok || queryArg == nil {
			return mcp.NewToolResultError("Query must be present"), nil