Metadata-Version: 2.4
Name: mtmt-mcp
Version: 0.1.1
Summary: A Model Context Protocol server for the Hungarian Science Bibliography (MTMT).
Project-URL: Documentation, https://mtmt.hu/dokumentumok/mtmt2_api_dokumentacio.pdf
Project-URL: Repository, https://github.com/attilaimre99/MTMT-MCP
Author: MTMT-MCP contributors
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright [yyyy] [name of copyright owner]
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
Keywords: bibliography,fastmcp,hungary,mcp,mtmt
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Requires-Dist: fastmcp<4,>=2.12
Requires-Dist: httpx<1,>=0.27
Provides-Extra: dev
Requires-Dist: pytest-asyncio<2,>=0.24; extra == 'dev'
Requires-Dist: pytest<9,>=8; extra == 'dev'
Requires-Dist: ruff>=0.9; extra == 'dev'
Description-Content-Type: text/markdown

# MTMT-MCP

A simple [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server for the
[Hungarian Science Bibliography (MTMT)](https://mtmt.hu/), built with Python and
[FastMCP](https://gofastmcp.com/).

MTMT-MCP lets MCP clients search the public MTMT catalogue and retrieve bibliographic
records, authors, journals, institutions, conferences, grants, and publishers. It is
read-only and does not require MTMT credentials for public records.

> [!IMPORTANT]
> This is an independent community project. It is not affiliated with or endorsed by MTMT.

## Features

- Search publications by title, author, journal, external identifier, year, university,
  and department.
- Resolve universities and organizational units to stable MTMT institution IDs.
- Resolve author profiles before listing a specific researcher's publications.
- Retrieve MTMT's official author summary metrics and both h-index variants.
- Fetch one publication or batch-fetch up to 20 known MTMT IDs.
- Traverse explicit incoming and outgoing MTMT citation links.
- Run advanced searches using native MTMT conditions.
- Retrieve public records by MTMT ID.
- Control response size with MTMT field selection.
- Use English or Hungarian response labels.
- Connect over MCP's standard input/output transport.

## Requirements

- Python 3.11 or newer
- An MCP-compatible client

## Installation

Install the latest release from [PyPI](https://pypi.org/project/mtmt-mcp/):

```bash
python -m pip install --upgrade mtmt-mcp
```

Run the installed server:

```bash
mtmt-mcp
```

You can also run the PyPI package in an isolated environment without installing it
permanently:

```bash
uvx mtmt-mcp
```

### Install from source

For development, clone the repository and install it in a virtual environment:

```bash
git clone https://github.com/attilaimre99/MTMT-MCP.git
cd MTMT-MCP
python -m venv .venv
```

On Linux or macOS:

```bash
source .venv/bin/activate
pip install -e .
```

On Windows PowerShell:

```powershell
.venv\Scripts\Activate.ps1
pip install -e .
```

Run the server:

```bash
mtmt-mcp
```

You can also run it without installing the command-line entry point:

```bash
python -m mtmt_mcp.server
```

## Expose the server through ngrok

The commands above use MCP's local stdio transport. To connect from a remote MCP client,
start FastMCP's HTTP transport and expose its port through ngrok.

In the first terminal, start the HTTP server on port 8000:

```bash
uv run python -c 'from mtmt_mcp.server import mcp; mcp.run(transport="http", host="127.0.0.1", port=8000)'
```

If the project environment is already activated, `python` can be used instead of
`uv run python`. The server should report that it is listening at
`http://127.0.0.1:8000/mcp`.

In a second terminal, start the tunnel. Use a reserved ngrok domain when one is available:

```bash
ngrok http --url=your-subdomain.ngrok-free.dev 8000
```

Without a reserved domain, let ngrok assign a temporary URL:

```bash
ngrok http 8000
```

Configure the remote MCP client with the public URL shown by ngrok and append `/mcp`:

```text
https://your-subdomain.ngrok-free.dev/mcp
```

Both terminal processes must remain running. Restarting a tunnel without a reserved domain
usually changes its public URL.

> [!WARNING]
> An ngrok URL exposes the MCP server to the internet. This project is read-only, but the
> HTTP endpoint does not add authentication. Use an authenticated gateway or equivalent
> access control before sharing the URL or running a long-lived deployment.

## MCP client configuration

After installing from PyPI, add the server command to the MCP client configuration:

```json
{
  "mcpServers": {
    "mtmt": {
      "command": "mtmt-mcp"
    }
  }
}
```

Alternatively, let `uvx` download and run the latest PyPI release in an isolated environment:

```json
{
  "mcpServers": {
    "mtmt": {
      "command": "uvx",
      "args": ["mtmt-mcp"]
    }
  }
}
```

For an editable source checkout, replace `/absolute/path/to/MTMT-MCP` with the local
repository path:

```json
{
  "mcpServers": {
    "mtmt": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/MTMT-MCP",
        "run",
        "mtmt-mcp"
      ]
    }
  }
}
```

If `uv` is not installed, point the client directly at the virtual environment's Python:

```json
{
  "mcpServers": {
    "mtmt": {
      "command": "/absolute/path/to/MTMT-MCP/.venv/bin/python",
      "args": ["-m", "mtmt_mcp.server"]
    }
  }
}
```

On Windows, the command path ends in `.venv\\Scripts\\python.exe`.

## Available tools

### `search_publications`

Search publications by any combination of title, author name, earliest year, and latest
year, journal, exact external identifier such as a DOI or ISBN, university MTMT ID, or
department MTMT ID. This is the primary tool for literature discovery. It returns compact
metadata, recorded institutional affiliations, and paging information; an agent can request
abstracts only when needed.

Example request:

```text
Find MTMT publications with "machine learning" in the title, published since 2022.
```

### `search_institutes`

Resolve a university, faculty, clinic, institute, department, or research-unit name to a
stable MTMT institution ID before filtering publications. Results include organizational
type, immediate parents, child count, active dates, and names in both Hungarian and English.

For reliable department filtering, use a two-step workflow:

1. Resolve the university and retain its MTMT ID.
2. Resolve the department with `within_university_mtid` set to that university ID.
3. Pass the selected IDs as `university_mtid` and `department_mtid` to
   `search_publications`.

University and department filters are hierarchy-aware: they include publications assigned
to the selected organization or any organizational unit below it in MTMT. MTMT affiliation
coverage depends on the institutions recorded on each authorship.

### `get_publication` and `get_publications`

Retrieve detailed metadata for one known publication, or batch-fetch up to 20 MTMT IDs.
The results include authorships, identifiers, publication type, journal or publisher,
open-access metadata, and citation counts. Abstracts are optional to keep agent context
manageable. The batch tool reports individual failures without discarding successful
records.

### `search_authors` and `get_author_publications`

First resolve a researcher's name to a stable MTMT author ID, then list publications
linked to that exact profile. This workflow is preferable to name-only publication
searches when authors have common names or several name variants.

### `get_author_metrics`

Read the public MTMT "összesítő táblázat" for an identified author. The result includes
the independent-citation and all-citation Hirsch indices, core scientific and overall
publication/citation totals, selected author-profile counts, and an optional category
breakdown. These are MTMT metrics—not estimates calculated from a capped search result.
MTMT's table notes state that the h-index is based on all scientific publications and
excludes citing dissertations and records classified as other publication types.

### `get_publication_connections`

Return publications recorded by MTMT as citing a source (`cited_by`) or publications
referenced from an MTMT citation record (`references`). Citation coverage depends on
MTMT's curated records; this tool is not a semantic similarity search.

### `search_mtmt`

Search any supported record collection using native MTMT query conditions. A condition
has the form `field;operator;value`. Conditions can be combined with `AND` or `OR`.

```text
resource_type: publication
conditions:
  - title;any;machine learning
  - publishedYear;ge;2022
sort:
  - publishedYear,desc
size: 10
```

Page numbers are one-based: use `page: 1` for the first page.

Common operators include `eq`, `ne`, `any`, `prefix`, `gt`, `ge`, `lt`, `le`, `in`,
`isnull`, and `notnull`. The fields and valid operators depend on the record type.

Supported collections are `publication`, `author`, `journal`, `institute`, `conference`,
`funding`, and `publisher`.

### `get_mtmt_record`

Retrieve one public record by its resource type and MTMT ID. Use `include_fields` to
keep large records focused, for example:

```text
resource_type: publication
mtid: 12345678
include_fields: title,publishedYear,authorships:1,identifiers
```

## Configuration

The defaults work with the public MTMT service. These optional environment variables are
available for development or self-hosted gateways:

| Variable | Default | Purpose |
| --- | --- | --- |
| `MTMT_API_BASE_URL` | `https://m2.mtmt.hu/api` | MTMT API base URL |
| `MTMT_TIMEOUT` | `30` | HTTP timeout in seconds |

## MTMT API documentation

The official MTMT2 API documentation is available here:

**[MTMT2 API documentation (PDF)](https://mtmt.hu/dokumentumok/mtmt2_api_dokumentacio.pdf)**

MTMT also publishes the current list of query operators at
[m2.mtmt.hu/api-docs/query-ops](https://m2.mtmt.hu/api-docs/query-ops).

The upstream API uses `application/vnd.mtmt2-1.0+json`, returns records inside a
`content` property, and includes `paging` metadata for collection searches. MTMT may cap
the total accessible result set; use narrow conditions and pagination for reliable calls.

## Development

Install the development dependencies and run the checks:

```bash
pip install -e ".[dev]"
ruff check .
pytest
```

Pull requests and pushes to `main` run Ruff, the test suite on Python 3.11 through 3.13,
and a package build. The release workflow runs when a GitHub release is published. It
requires a `v<project-version>` tag, attaches the wheel and source distribution to the
GitHub release, and publishes them to PyPI through trusted publishing.

Before the first release, create a `pypi` GitHub environment and configure a PyPI trusted
publisher for this repository, the `release.yml` workflow, and that environment. Keep the
versions in `pyproject.toml` and `src/mtmt_mcp/__init__.py` synchronized.

Create subsequent releases with the version-bump script:

```bash
uv run python scripts/bump_version.py patch --dry-run
uv run python scripts/bump_version.py patch
```

Replace `patch` with `minor` or `major` as needed. The script requires a clean local `main`
that exactly matches `origin/main`. It updates both version declarations and `uv.lock`, runs
Ruff and the test suite, commits and pushes the bump, creates and pushes the matching `vX.Y.Z`
tag, and publishes a GitHub release. Publishing that release triggers the PyPI workflow.

## License

Licensed under the [Apache License 2.0](LICENSE).
