Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions mcp_graphql/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from functools import partial
from logging import INFO, basicConfig, getLogger
from logging import INFO, WARNING, basicConfig, getLogger
from typing import Any, cast

from gql import Client
Expand All @@ -14,6 +14,8 @@
GraphQLArgumentMap,
GraphQLEnumType,
GraphQLField,
GraphQLInputField,
GraphQLInputObjectType,
GraphQLInputType,
GraphQLInterfaceType,
GraphQLList,
Expand Down Expand Up @@ -50,6 +52,8 @@
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = getLogger(__name__)
# Silence INFO logs from the gql AIOHTTP transport
getLogger("gql.transport.aiohttp").setLevel(WARNING)


class UnknownGraphQLTypeError(Exception):
Expand Down Expand Up @@ -103,7 +107,7 @@ def _convert_scalar_to_json_schema(gql_scalar: GraphQLScalarType) -> JsonSchema:
return {"type": "string", "description": f"GraphQL scalar: {gql_scalar!s}"}


def convert_type_to_json_schema(
def convert_type_to_json_schema( # noqa: C901
gql_type: GraphQLInputType | GraphQLArgument,
max_depth: int = 3,
current_depth: int = 1,
Expand Down Expand Up @@ -176,9 +180,19 @@ def convert_type_to_json_schema(
schema = convert_type_to_json_schema(gql_type.type)
if gql_type.description is not None:
schema["description"] = gql_type.description

elif isinstance(gql_type, GraphQLInputObjectType):
schema = {
"type": "object",
"properties": {
field_name: convert_type_to_json_schema(field_type)
for field_name, field_type in gql_type.fields.items()
},
}
elif isinstance(gql_type, GraphQLInputField):
schema = convert_type_to_json_schema(gql_type.type)
else:
# Unknown / unsupported
logger.error("Unknown GraphQL type: %s", gql_type.__class__.__name__)
raise UnknownGraphQLTypeError(gql_type)

return schema
Expand Down
3 changes: 2 additions & 1 deletion nix/pkgs/deploy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ pkgs.writeShellApplication {
name = "mcp_graphql-deploy";
runtimeInputs = pkgs.lib.flatten [
pkgs.uv
pkgs.sops
lib'.envs.default
];
text = ''
pyproject_toml="pyproject.toml"

if ! git diff HEAD~1 HEAD -- "''${pyproject_toml}" | grep -q '^[-+]version'; then
: && info "''${pyproject_toml} version has not changed. Skipping deployment." \
echo "''${pyproject_toml} version has not changed. Skipping deployment." \
&& return 0
fi

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "mcp-graphql"
version = "0.3.1"
description = "Add your description here"
version = "0.3.2"
description = "MCP server for GraphQL"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.