# oisee/odata_mcp architecture

> Architecture diagram of the GitHub repository oisee/odata_mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oisee/odata_mcp
- Repository: https://github.com/oisee/odata_mcp

## Overview

1. **What this repository is**
   - This is a Python bridge that sits between an external **OData v2 service** and **MCP clients**.
   - Its job is to inspect OData metadata at runtime and expose that service as a set of dynamically generated MCP tools.

2. **Primary runtime entrypoint**
   - `odata_mcp.py` is the executable front door.
   - It reads CLI flags and environment variables, builds the service/auth/configuration context, then starts the MCP server over the selected transport.

3. **Core library boundary**
   - The main implementation lives in `odata_mcp_lib/`, which is organized as a small pipeline:
     - **metadata discovery**
     - **OData HTTP access**
     - **tool generation / MCP bridging**
     - **transport exposure**
   - `__init__.py` provides the public import surface for consumers.

4. **Metadata-driven tool synthesis**
   - `metadata_parser.py` fetches and parses the service’s `$metadata` document.
   - That parsed schema is turned into tool definitions for entity sets, functions, and a service-info tool.
   - The bridge is dynamic: tool shape depends on the target OData service rather than a fixed API.

5. **MCP bridge layer**
   - `bridge.py` is the central orchestration layer.
   - It maps OData constructs into MCP tools such as list/filter, count, get, create, update, delete, and function-import operations.
   - It also applies repo-specific policies like read-only modes, operation filtering, tool naming, entity/function selection, and response limits.

6. **Outbound OData client boundary**
   - `client.py` handles HTTP communication with the OData service itself.
   - This is where authentication, request/response handling, error propagation, and OData-specific behavior like CSRF-token management are concentrated.
   - The bridge never talks to the remote service directly; it goes through this client layer.

7. **Authentication subsystem**
   - `oauth_handler.py` supports OAuth 2.0 client-credentials flow and token refresh.
   - The README also describes basic auth and cookie-based auth, so auth is a configurable boundary before any OData request is issued.
   - This is important architecturally because it affects every outbound request path.

8. **Data normalization and service quirks**
   - `guid_handler.py` normalizes GUID formats, including base64-style GUIDs seen in some OData services.
   - The repo also documents conversion support for legacy SAP date formats and decimal-field handling.
   - These transformations are part of the request/response adaptation layer between OData payloads and MCP tool inputs/outputs.

9. **Tool naming, filtering, and hints**
   - `name_shortener.py` and `hint_manager.py` shape the generated tool surface.
   - Tool names can be prefixed/postfixed, shortened, or sorted; generation can be limited to selected entities/functions or operation types.
   - Hint data from `hints.json` is merged into service info responses to guide users around service-specific quirks.

10. **Transport layer**
   - `odata_mcp_lib/transport/stdio.py` exposes the MCP server over standard input/output for desktop-style MCP clients.
   - `odata_mcp_lib/transport/http_sse.py` exposes the same MCP bridge over HTTP/SSE for browser/web clients.
   - This is the main inbound boundary: clients talk MCP to the transport, and the transport forwards into the bridge.

11. **Shared models and constants**
   - `models.py` defines structured internal data types used across parsing, bridging, and transport.
   - `constants.py` centralizes OData type mappings and namespace-related constants so schema interpretation is consistent across modules.

12. **Operational controls**
   - The repo emphasizes configurable safety and scale controls: read-only modes, allow/deny operation sets, max response size, max items, metadata inclusion, verbose error output, and MCP tracing.
   - These controls mainly affect the bridge’s generated tool set and the client’s response shaping, not the transport itself.

13. **Testing and validation**
   - The repository has focused tests for OData behavior, transports, OAuth, security, filtering, URL/query encoding, sorting, and wildcard matching.
   - The test files indicate the architecture is validated across both the protocol boundary (MCP transport) and the service boundary (real OData interactions).

14. **External dependencies and integration points**
   - The system depends on a live **OData v2 backend** and an **MCP runtime/client**.
   - OAuth integration adds a separate dependency on an OAuth token endpoint, while the HTTP/SSE mode adds a browser/web-client integration path.

Main entry points: [`odata_mcp_lib/bridge.py`](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/bridge.py) (Bridge), [`odata_mcp.py`](https://github.com/oisee/odata_mcp/blob/main/odata_mcp.py) (odata_mcp.py), [`odata_mcp_lib/client.py`](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/client.py) (OData client), [`odata_mcp_lib/__init__.py`](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/__init__.py) (__init__)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_entry["Entrypoint"]
  node_odata_mcp_py["odata_mcp.py<br/>CLI bootstrap<br/>[odata_mcp.py]"]
end

subgraph group_g_core["Core Library"]
  node_lib_init["__init__<br/>public API<br/>[__init__.py]"]
  node_metadata_parser["Metadata parser<br/>schema discovery<br/>[metadata_parser.py]"]
  node_bridge{{"Bridge<br/>tool orchestration<br/>[bridge.py]"}}
  node_client["OData client<br/>http adapter<br/>[client.py]"]
  node_oauth_handler["OAuth handler<br/>auth flow<br/>[oauth_handler.py]"]
  node_guid_handler(("GUID handler<br/>value normalization<br/>[guid_handler.py]"))
  node_hint_manager["Hint manager<br/>service hints<br/>[hint_manager.py]"]
  node_name_shortener(("Name shortener<br/>tool naming<br/>[name_shortener.py]"))
  node_models[("Models<br/>internal types<br/>[models.py]")]
  node_constants(("Constants<br/>type map<br/>[constants.py]"))
end

subgraph group_g_transport["Transport"]
  node_stdio_transport["stdio<br/>[stdio.py]"]
  node_http_sse_transport["http+sse<br/>MCP web transport<br/>[http_sse.py]"]
  node_transport_init["transport/__init__<br/>transport API<br/>[__init__.py]"]
end

node_odata_mcp_py -->|"boots"| node_bridge
node_odata_mcp_py -->|"configures"| node_client
node_odata_mcp_py -->|"selects"| node_stdio_transport
node_odata_mcp_py -->|"selects"| node_http_sse_transport
node_odata_mcp_py -->|"auth setup"| node_oauth_handler
node_lib_init -->|"exports"| node_bridge
node_lib_init -->|"exports"| node_client
node_lib_init -->|"exports"| node_metadata_parser
node_lib_init -->|"exports"| node_models
node_metadata_parser -->|"builds"| node_models
node_metadata_parser -->|"uses"| node_constants
node_bridge -->|"discovers"| node_metadata_parser
node_bridge -->|"calls"| node_client
node_bridge -->|"normalizes"| node_guid_handler
node_bridge -->|"enriches"| node_hint_manager
node_bridge -->|"names"| node_name_shortener
node_bridge -->|"uses"| node_models
node_client -->|"authenticates"| node_oauth_handler
node_client -->|"interprets"| node_constants
node_stdio_transport -->|"serves"| node_bridge
node_http_sse_transport -->|"serves"| node_bridge
node_transport_init -->|"exports"| node_stdio_transport
node_transport_init -->|"exports"| node_http_sse_transport

click node_odata_mcp_py "https://github.com/oisee/odata_mcp/blob/main/odata_mcp.py"
click node_lib_init "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/__init__.py"
click node_metadata_parser "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/metadata_parser.py"
click node_bridge "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/bridge.py"
click node_client "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/client.py"
click node_oauth_handler "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/oauth_handler.py"
click node_guid_handler "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/guid_handler.py"
click node_hint_manager "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/hint_manager.py"
click node_name_shortener "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/name_shortener.py"
click node_models "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/models.py"
click node_constants "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/constants.py"
click node_stdio_transport "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/transport/stdio.py"
click node_http_sse_transport "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/transport/http_sse.py"
click node_transport_init "https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/transport/__init__.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_odata_mcp_py toneBlue
class node_lib_init,node_metadata_parser,node_bridge,node_client,node_oauth_handler,node_guid_handler,node_hint_manager,node_name_shortener,node_models,node_constants toneAmber
class node_stdio_transport,node_http_sse_transport,node_transport_init toneMint
```

## Components

### Entrypoint

Executable front door and runtime bootstrapping.

- [odata_mcp.py](https://github.com/oisee/odata_mcp/blob/main/odata_mcp.py): CLI bootstrap · Reads flags/env, builds config/auth context, and starts the server. · `odata_mcp.py`

### Core Library

Metadata-driven MCP bridge, OData client, and shared support code.

- [__init__](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/__init__.py): public API · Public import surface for the library. · `odata_mcp_lib/__init__.py`
- [Metadata parser](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/metadata_parser.py): schema discovery · Fetches and parses OData $metadata into structured service schema. · `odata_mcp_lib/metadata_parser.py`
- [Bridge](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/bridge.py): tool orchestration · Maps OData constructs into MCP tools and applies policy controls. · `odata_mcp_lib/bridge.py`
- [OData client](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/client.py): http adapter · Handles outbound OData requests, auth attachment, CSRF, and error handling. · `odata_mcp_lib/client.py`
- [OAuth handler](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/oauth_handler.py): auth flow · Supports OAuth client-credentials and token refresh. · `odata_mcp_lib/oauth_handler.py`
- [GUID handler](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/guid_handler.py): value normalization · Normalizes GUID formats used by OData services. · `odata_mcp_lib/guid_handler.py`
- [Hint manager](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/hint_manager.py): service hints · Merges hint metadata into service info responses. · `odata_mcp_lib/hint_manager.py`
- [Name shortener](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/name_shortener.py): tool naming · Shapes generated tool names and ordering. · `odata_mcp_lib/name_shortener.py`
- [Models](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/models.py): internal types · Shared structured data types used across parsing, bridging, and transport. · `odata_mcp_lib/models.py`
- [Constants](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/constants.py): type map · Central OData type and namespace constants. · `odata_mcp_lib/constants.py`

### Transport

Inbound MCP exposure over stdio and HTTP/SSE.

- [stdio](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/transport/stdio.py): MCP stdio · Exposes MCP over standard input/output. · `odata_mcp_lib/transport/stdio.py`
- [http+sse](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/transport/http_sse.py): MCP web transport · Exposes MCP over HTTP and Server-Sent Events. · `odata_mcp_lib/transport/http_sse.py`
- [transport/__init__](https://github.com/oisee/odata_mcp/blob/main/odata_mcp_lib/transport/__init__.py): transport API · Transport package export surface. · `odata_mcp_lib/transport/__init__.py`

## Connections

- odata_mcp.py → Bridge: boots · Main entrypoint initializes and starts the bridge.
- odata_mcp.py → OData client: configures · Entry script builds service and auth context for the client.
- odata_mcp.py → stdio: selects · Chooses an MCP transport based on runtime flags.
- odata_mcp.py → http+sse: selects · Chooses an HTTP/SSE transport when requested.
- odata_mcp.py → OAuth handler: auth setup · Loads OAuth-related configuration for outbound requests.
- __init__ → Bridge: exports · Re-exports core bridge functionality.
- __init__ → OData client: exports · Re-exports core client functionality.
- __init__ → Metadata parser: exports · Re-exports metadata parsing utilities.
- __init__ → Models: exports · Re-exports shared types.
- Metadata parser → Models: builds · Parsed metadata is converted into structured internal models.
- Metadata parser → Constants: uses · Type interpretation relies on shared OData constants.
- Bridge → Metadata parser: discovers · Bridge starts from live service metadata.
- Bridge → OData client: calls · All OData operations flow through the outbound client.
- Bridge → GUID handler: normalizes · Request and response values are adjusted for GUID quirks.
- Bridge → Hint manager: enriches · Service info and tool guidance are augmented with hints.
- Bridge → Name shortener: names · Generated tools are named and ordered through naming policy.
- Bridge → Models: uses · Bridge logic exchanges structured internal models.
- OData client → OAuth handler: authenticates · Client delegates OAuth token acquisition and refresh.
- OData client → Constants: interprets · Client depends on shared OData type conventions.
- stdio → Bridge: serves · stdio transport forwards MCP requests into the bridge.
- http+sse → Bridge: serves · HTTP/SSE transport forwards MCP requests into the bridge.
- transport/__init__ → stdio: exports · Transport package exposes stdio implementation.
- transport/__init__ → http+sse: exports · Transport package exposes HTTP/SSE implementation.
