markdown-ai-mcp 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markdown_ai_mcp-1.0.0/.github/workflows/mcp-smithery-publish.yml +40 -0
- markdown_ai_mcp-1.0.0/.gitignore +4 -0
- markdown_ai_mcp-1.0.0/.mcp.json +77 -0
- markdown_ai_mcp-1.0.0/CODE_OF_CONDUCT.md +18 -0
- markdown_ai_mcp-1.0.0/CONTRIBUTING.md +21 -0
- markdown_ai_mcp-1.0.0/Dockerfile.glama +20 -0
- markdown_ai_mcp-1.0.0/LICENSE +4 -0
- markdown_ai_mcp-1.0.0/PKG-INFO +19 -0
- markdown_ai_mcp-1.0.0/README.md +52 -0
- markdown_ai_mcp-1.0.0/SECURITY.md +16 -0
- markdown_ai_mcp-1.0.0/glama.json +10 -0
- markdown_ai_mcp-1.0.0/mcp-wrapper.py +85 -0
- markdown_ai_mcp-1.0.0/package.json +30 -0
- markdown_ai_mcp-1.0.0/pyproject.toml +27 -0
- markdown_ai_mcp-1.0.0/pytest.ini +3 -0
- markdown_ai_mcp-1.0.0/server.py +198 -0
- markdown_ai_mcp-1.0.0/smithery.yaml +40 -0
- markdown_ai_mcp-1.0.0/tests/test_server.py +55 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Publish to Smithery
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions: {}
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
name: Publish MCP Server to Smithery
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
attestations: write
|
|
16
|
+
id-token: write
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout repository
|
|
19
|
+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
|
20
|
+
with:
|
|
21
|
+
persist-credentials: false
|
|
22
|
+
|
|
23
|
+
- name: Setup Node.js
|
|
24
|
+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
|
|
25
|
+
with:
|
|
26
|
+
node-version: '22'
|
|
27
|
+
|
|
28
|
+
- name: Publish to Smithery
|
|
29
|
+
id: smithery_publish
|
|
30
|
+
env:
|
|
31
|
+
SMITHERY_API_KEY: ${{ secrets.SMITHERY_API_KEY }}
|
|
32
|
+
run: |
|
|
33
|
+
npx @smithery/cli mcp publish "https://github.com/${{ github.repository }}" -n nicholastempleman/${{ github.event.repository.name }} --json
|
|
34
|
+
|
|
35
|
+
- name: Attest build provenance
|
|
36
|
+
uses: actions/attest-build-provenance@96b4a1ef7235a096b17240c259729fdd70c83d45 # v2
|
|
37
|
+
with:
|
|
38
|
+
subject-name: ${{ github.repository }}
|
|
39
|
+
subject-digest: sha256:${{ github.sha }}
|
|
40
|
+
push-to-registry: false
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-ai-mcp",
|
|
3
|
+
"description": "Markdown Ai MCP server. Tools: convert to html, generate toc, lint markdown. Built by MEOK AI Labs.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"tools": [
|
|
6
|
+
{
|
|
7
|
+
"name": "convert_to_html",
|
|
8
|
+
"description": "Convert Markdown to HTML (supports headers, bold, italic, links, code, lists).",
|
|
9
|
+
"parameters": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"markdown": {
|
|
13
|
+
"type": "string"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"required": [
|
|
17
|
+
"markdown"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "generate_toc",
|
|
23
|
+
"description": "Generate a table of contents from Markdown headers.",
|
|
24
|
+
"parameters": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"properties": {
|
|
27
|
+
"markdown": {
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"max_depth": {
|
|
31
|
+
"type": "integer"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"required": [
|
|
35
|
+
"markdown"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "lint_markdown",
|
|
41
|
+
"description": "Lint Markdown for common issues.",
|
|
42
|
+
"parameters": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"properties": {
|
|
45
|
+
"markdown": {
|
|
46
|
+
"type": "string"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"required": [
|
|
50
|
+
"markdown"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"name": "format_table",
|
|
56
|
+
"description": "Format data as a Markdown table. headers: comma-separated. rows: semicolon-separated rows of comma-separated values. alignment: L/C/R per column.",
|
|
57
|
+
"parameters": {
|
|
58
|
+
"type": "object",
|
|
59
|
+
"properties": {
|
|
60
|
+
"headers": {
|
|
61
|
+
"type": "string"
|
|
62
|
+
},
|
|
63
|
+
"rows": {
|
|
64
|
+
"type": "string"
|
|
65
|
+
},
|
|
66
|
+
"alignment": {
|
|
67
|
+
"type": "string"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"required": [
|
|
71
|
+
"headers",
|
|
72
|
+
"rows"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our project a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
|
|
6
|
+
|
|
7
|
+
## Our Standards
|
|
8
|
+
|
|
9
|
+
Examples of behavior that contributes to a positive environment:
|
|
10
|
+
- Demonstrating empathy and kindness toward other people
|
|
11
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
|
12
|
+
- Giving and gracefully accepting constructive feedback
|
|
13
|
+
|
|
14
|
+
## Enforcement
|
|
15
|
+
|
|
16
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nicholas@meok.ai.
|
|
17
|
+
|
|
18
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Contributing to MEOK AI Labs MCP Servers
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing!
|
|
4
|
+
|
|
5
|
+
## How to Contribute
|
|
6
|
+
|
|
7
|
+
1. Fork the repository.
|
|
8
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`).
|
|
9
|
+
3. Commit your changes (`git commit -m 'feat: add amazing feature'`).
|
|
10
|
+
4. Push to the branch (`git push origin feature/amazing-feature`).
|
|
11
|
+
5. Open a Pull Request.
|
|
12
|
+
|
|
13
|
+
## Code Style
|
|
14
|
+
|
|
15
|
+
- Follow PEP 8 for Python code.
|
|
16
|
+
- Keep tool interfaces backward-compatible when possible.
|
|
17
|
+
- Add tests for new functionality.
|
|
18
|
+
|
|
19
|
+
## Questions?
|
|
20
|
+
|
|
21
|
+
Reach out at nicholas@meok.ai.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
FROM python:3.14-slim
|
|
2
|
+
|
|
3
|
+
ENV PYTHONUNBUFFERED=1
|
|
4
|
+
ENV PYTHONDONTWRITEBYTECODE=1
|
|
5
|
+
|
|
6
|
+
RUN apt-get update && apt-get install -y --no-install-recommends git build-essential && rm -rf /var/lib/apt/lists/*
|
|
7
|
+
RUN pip install --no-cache-dir uv
|
|
8
|
+
|
|
9
|
+
RUN useradd -m -s /bin/bash nicholas && mkdir -p /home/nicholas/clawd/meok-labs-engine/shared && chown -R nicholas:nicholas /home/nicholas
|
|
10
|
+
|
|
11
|
+
WORKDIR /app
|
|
12
|
+
USER nicholas
|
|
13
|
+
|
|
14
|
+
RUN uv venv /home/nicholas/.venv
|
|
15
|
+
ENV PATH="/home/nicholas/.venv/bin:$PATH"
|
|
16
|
+
|
|
17
|
+
COPY --chown=nicholas:nicholas . /app
|
|
18
|
+
RUN uv pip install -e .
|
|
19
|
+
|
|
20
|
+
CMD ["python", "mcp-wrapper.py"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: markdown-ai-mcp
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Markdown Ai MCP server. Tools: convert to html, generate toc, lint markdown. Built by MEOK AI Labs.
|
|
5
|
+
Project-URL: Homepage, https://meok.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/CSOAI-ORG/markdown-ai-mcp
|
|
7
|
+
Author-email: MEOK AI Labs <nicholas@meok.ai>
|
|
8
|
+
License: MIT License
|
|
9
|
+
Copyright (c) 2026 MEOK AI Labs (meok.ai)
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software to deal in the Software without restriction.
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS".
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: ai,markdown,mcp,meok
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: mcp>=1.0.0
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Markdown AI
|
|
2
|
+
|
|
3
|
+
> By [MEOK AI Labs](https://meok.ai) — Markdown processing, conversion, and linting tools
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install markdown-ai-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python server.py
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Tools
|
|
18
|
+
|
|
19
|
+
### `convert_to_html`
|
|
20
|
+
Convert Markdown to HTML (supports headers, bold, italic, links, code, lists).
|
|
21
|
+
|
|
22
|
+
**Parameters:**
|
|
23
|
+
- `markdown` (str): Markdown text to convert
|
|
24
|
+
|
|
25
|
+
### `generate_toc`
|
|
26
|
+
Generate a table of contents from Markdown headers.
|
|
27
|
+
|
|
28
|
+
**Parameters:**
|
|
29
|
+
- `markdown` (str): Markdown text
|
|
30
|
+
- `max_depth` (int): Maximum heading depth (default: 3)
|
|
31
|
+
|
|
32
|
+
### `lint_markdown`
|
|
33
|
+
Lint Markdown for common issues (line length, trailing whitespace, heading spacing, tabs, broken links).
|
|
34
|
+
|
|
35
|
+
**Parameters:**
|
|
36
|
+
- `markdown` (str): Markdown text to lint
|
|
37
|
+
|
|
38
|
+
### `format_table`
|
|
39
|
+
Format data as a Markdown table.
|
|
40
|
+
|
|
41
|
+
**Parameters:**
|
|
42
|
+
- `headers` (str): Comma-separated column headers
|
|
43
|
+
- `rows` (str): Semicolon-separated rows of comma-separated values
|
|
44
|
+
- `alignment` (str): L/C/R per column
|
|
45
|
+
|
|
46
|
+
## Authentication
|
|
47
|
+
|
|
48
|
+
Free tier: 15 calls/day. Upgrade at [meok.ai/pricing](https://meok.ai/pricing) for unlimited access.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT — MEOK AI Labs
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
| Version | Supported |
|
|
6
|
+
| ------- | ------------------ |
|
|
7
|
+
| 1.0.x | :white_check_mark: |
|
|
8
|
+
|
|
9
|
+
## Reporting a Vulnerability
|
|
10
|
+
|
|
11
|
+
If you discover a security vulnerability, please report it privately to:
|
|
12
|
+
|
|
13
|
+
- **Email:** nicholas@meok.ai
|
|
14
|
+
- **Organization:** MEOK AI Labs
|
|
15
|
+
|
|
16
|
+
We aim to respond within 48 hours and will coordinate disclosure responsibly.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-ai-mcp",
|
|
3
|
+
"description": "MEOK AI Labs \u2014 markdown-ai-mcp",
|
|
4
|
+
"vendor": "MEOK AI Labs",
|
|
5
|
+
"homepage": "https://meok.ai",
|
|
6
|
+
"repository": "https://github.com/CSOAI-ORG/markdown-ai-mcp",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"runtime": "python",
|
|
9
|
+
"entryPoint": "mcp-wrapper.py"
|
|
10
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""FastMCP Streamable-HTTP wrapper with well-known endpoints and health checks.
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
python /path/to/mcp-streamable-http-wrapper.py
|
|
6
|
+
|
|
7
|
+
This imports `mcp` from `server.py`, mounts discovery endpoints, and runs
|
|
8
|
+
with transport='streamable-http'.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
sys.path.insert(0, os.path.expanduser("~/clawd/meok-labs-engine/shared"))
|
|
16
|
+
sys.path.insert(0, os.getcwd())
|
|
17
|
+
|
|
18
|
+
from starlette.requests import Request
|
|
19
|
+
from starlette.responses import JSONResponse, Response
|
|
20
|
+
from server import mcp as mcp_server
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
SERVICE_NAME = os.path.basename(os.getcwd())
|
|
24
|
+
REPO_URL = f"https://github.com/CSOAI-ORG/{SERVICE_NAME}"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@mcp_server.custom_route("/.well-known/mcp/server-card.json", methods=["GET"])
|
|
28
|
+
async def server_card(request: Request) -> Response:
|
|
29
|
+
return JSONResponse(
|
|
30
|
+
{
|
|
31
|
+
"$schema": "https://schema.smithery.ai/server-card.json",
|
|
32
|
+
"version": "1.0.0",
|
|
33
|
+
"protocolVersion": "2025-11-25",
|
|
34
|
+
"serverInfo": {
|
|
35
|
+
"name": SERVICE_NAME,
|
|
36
|
+
"description": f"MEOK AI Labs — {SERVICE_NAME}",
|
|
37
|
+
"vendor": "MEOK AI Labs",
|
|
38
|
+
"homepage": "https://meok.ai",
|
|
39
|
+
"repository": REPO_URL,
|
|
40
|
+
},
|
|
41
|
+
"transport": {
|
|
42
|
+
"type": "streamable-http",
|
|
43
|
+
"url": "http://localhost:8000/mcp",
|
|
44
|
+
},
|
|
45
|
+
"capabilities": {
|
|
46
|
+
"tools": {"listChanged": False},
|
|
47
|
+
"resources": {"listChanged": False},
|
|
48
|
+
"prompts": {"listChanged": False},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
headers={
|
|
52
|
+
"Access-Control-Allow-Origin": "*",
|
|
53
|
+
"Cache-Control": "public, max-age=3600",
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@mcp_server.custom_route("/.well-known/mcp", methods=["GET"])
|
|
59
|
+
async def mcp_manifest(request: Request) -> Response:
|
|
60
|
+
return JSONResponse(
|
|
61
|
+
{
|
|
62
|
+
"mcp_version": "2025-11-25",
|
|
63
|
+
"endpoints": [
|
|
64
|
+
{
|
|
65
|
+
"type": "streamable-http",
|
|
66
|
+
"path": "/mcp",
|
|
67
|
+
"url": "http://localhost:8000/mcp",
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
headers={
|
|
72
|
+
"Access-Control-Allow-Origin": "*",
|
|
73
|
+
"Cache-Control": "public, max-age=3600",
|
|
74
|
+
},
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@mcp_server.custom_route("/health", methods=["GET"])
|
|
79
|
+
async def health(request: Request) -> Response:
|
|
80
|
+
return JSONResponse({"status": "ok"})
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
if __name__ == "__main__":
|
|
84
|
+
mcp_server.settings.host = "0.0.0.0"
|
|
85
|
+
mcp_server.run(transport="streamable-http")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "markdown-ai-mcp",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Markdown Ai MCP server. Tools: convert to html, generate toc, lint markdown. Built by MEOK AI Labs.",
|
|
5
|
+
"main": "server.py",
|
|
6
|
+
"mcp": {
|
|
7
|
+
"name": "markdown",
|
|
8
|
+
"vendor": "MEOK AI Labs",
|
|
9
|
+
"homepage": "https://meok.ai",
|
|
10
|
+
"repository": "https://github.com/CSOAI-ORG/markdown-ai-mcp",
|
|
11
|
+
"runtime": "python",
|
|
12
|
+
"tags": [
|
|
13
|
+
"mcp",
|
|
14
|
+
"mcp-server",
|
|
15
|
+
"meok-ai-labs",
|
|
16
|
+
"ai-tools"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"mcp",
|
|
21
|
+
"mcp-server",
|
|
22
|
+
"meok-ai-labs"
|
|
23
|
+
],
|
|
24
|
+
"author": "MEOK AI Labs <nicholas@meok.ai>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/CSOAI-ORG/markdown-ai-mcp"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
[project]
|
|
5
|
+
name = "markdown-ai-mcp"
|
|
6
|
+
version = "1.0.0"
|
|
7
|
+
description = "Markdown Ai MCP server. Tools: convert to html, generate toc, lint markdown. Built by MEOK AI Labs."
|
|
8
|
+
license = {file = "LICENSE"}
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
authors = [{name = "MEOK AI Labs", email = "nicholas@meok.ai"}]
|
|
11
|
+
dependencies = ["mcp>=1.0.0"]
|
|
12
|
+
keywords = ["mcp", "ai", "meok", "markdown"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Topic :: Software Development :: Libraries",
|
|
18
|
+
]
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://meok.ai"
|
|
21
|
+
Repository = "https://github.com/CSOAI-ORG/markdown-ai-mcp"
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
packages = ["."]
|
|
24
|
+
only-include = ["server.py"]
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
markdown_ai_mcp = "server:main"
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"""Markdown AI MCP Server — Markdown processing tools."""
|
|
2
|
+
|
|
3
|
+
import sys, os
|
|
4
|
+
sys.path.insert(0, os.path.expanduser('~/clawd/meok-labs-engine/shared'))
|
|
5
|
+
from auth_middleware import check_access
|
|
6
|
+
|
|
7
|
+
import re
|
|
8
|
+
import time
|
|
9
|
+
from typing import Any
|
|
10
|
+
from mcp.server.fastmcp import FastMCP
|
|
11
|
+
|
|
12
|
+
import json
|
|
13
|
+
from datetime import datetime, timezone
|
|
14
|
+
from collections import defaultdict
|
|
15
|
+
|
|
16
|
+
FREE_DAILY_LIMIT = 15
|
|
17
|
+
_usage = defaultdict(list)
|
|
18
|
+
def _rl(c="anon"):
|
|
19
|
+
now = datetime.now(timezone.utc)
|
|
20
|
+
_usage[c] = [t for t in _usage[c] if (now-t).total_seconds() < 86400]
|
|
21
|
+
if len(_usage[c]) >= FREE_DAILY_LIMIT: return json.dumps({"error": f"Limit {FREE_DAILY_LIMIT}/day"})
|
|
22
|
+
_usage[c].append(now); return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
mcp = FastMCP("markdown-ai", instructions="MEOK AI Labs MCP Server")
|
|
26
|
+
_calls: dict[str, list[float]] = {}
|
|
27
|
+
DAILY_LIMIT = 50
|
|
28
|
+
|
|
29
|
+
def _rate_check(tool: str) -> bool:
|
|
30
|
+
now = time.time()
|
|
31
|
+
_calls.setdefault(tool, [])
|
|
32
|
+
_calls[tool] = [t for t in _calls[tool] if t > now - 86400]
|
|
33
|
+
if len(_calls[tool]) >= DAILY_LIMIT:
|
|
34
|
+
return False
|
|
35
|
+
_calls[tool].append(now)
|
|
36
|
+
return True
|
|
37
|
+
|
|
38
|
+
@mcp.tool()
|
|
39
|
+
def convert_to_html(markdown: str, api_key: str = "") -> dict[str, Any]:
|
|
40
|
+
"""Convert Markdown to HTML (supports headers, bold, italic, links, code, lists)."""
|
|
41
|
+
allowed, msg, tier = check_access(api_key)
|
|
42
|
+
if not allowed:
|
|
43
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
44
|
+
if err := _rl(): return err
|
|
45
|
+
|
|
46
|
+
if not _rate_check("convert_to_html"):
|
|
47
|
+
return {"error": "Rate limit exceeded (50/day)"}
|
|
48
|
+
html = markdown
|
|
49
|
+
# Code blocks first
|
|
50
|
+
html = re.sub(r'```(\w*)\n(.*?)```', lambda m: f'<pre><code class="language-{m.group(1)}">{m.group(2)}</code></pre>', html, flags=re.DOTALL)
|
|
51
|
+
html = re.sub(r'`([^`]+)`', r'<code>\1</code>', html)
|
|
52
|
+
# Headers
|
|
53
|
+
for i in range(6, 0, -1):
|
|
54
|
+
html = re.sub(rf'^{"#" * i}\s+(.+)$', rf'<h{i}>\1</h{i}>', html, flags=re.MULTILINE)
|
|
55
|
+
# Bold and italic
|
|
56
|
+
html = re.sub(r'\*\*\*(.+?)\*\*\*', r'<strong><em>\1</em></strong>', html)
|
|
57
|
+
html = re.sub(r'\*\*(.+?)\*\*', r'<strong>\1</strong>', html)
|
|
58
|
+
html = re.sub(r'\*(.+?)\*', r'<em>\1</em>', html)
|
|
59
|
+
# Links and images
|
|
60
|
+
html = re.sub(r'!\[([^\]]*)\]\(([^)]+)\)', r'<img src="\2" alt="\1">', html)
|
|
61
|
+
html = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'<a href="\2">\1</a>', html)
|
|
62
|
+
# Horizontal rule
|
|
63
|
+
html = re.sub(r'^---+$', '<hr>', html, flags=re.MULTILINE)
|
|
64
|
+
# Blockquote
|
|
65
|
+
html = re.sub(r'^>\s*(.+)$', r'<blockquote>\1</blockquote>', html, flags=re.MULTILINE)
|
|
66
|
+
# Unordered lists
|
|
67
|
+
lines = html.split("\n")
|
|
68
|
+
result, in_ul, in_ol = [], False, False
|
|
69
|
+
for line in lines:
|
|
70
|
+
ul_match = re.match(r'^[\-\*]\s+(.+)$', line)
|
|
71
|
+
ol_match = re.match(r'^\d+\.\s+(.+)$', line)
|
|
72
|
+
if ul_match:
|
|
73
|
+
if not in_ul:
|
|
74
|
+
result.append("<ul>")
|
|
75
|
+
in_ul = True
|
|
76
|
+
result.append(f" <li>{ul_match.group(1)}</li>")
|
|
77
|
+
elif ol_match:
|
|
78
|
+
if not in_ol:
|
|
79
|
+
result.append("<ol>")
|
|
80
|
+
in_ol = True
|
|
81
|
+
result.append(f" <li>{ol_match.group(1)}</li>")
|
|
82
|
+
else:
|
|
83
|
+
if in_ul:
|
|
84
|
+
result.append("</ul>")
|
|
85
|
+
in_ul = False
|
|
86
|
+
if in_ol:
|
|
87
|
+
result.append("</ol>")
|
|
88
|
+
in_ol = False
|
|
89
|
+
if line.strip():
|
|
90
|
+
result.append(f"<p>{line}</p>" if not line.startswith("<") else line)
|
|
91
|
+
else:
|
|
92
|
+
result.append("")
|
|
93
|
+
if in_ul: result.append("</ul>")
|
|
94
|
+
if in_ol: result.append("</ol>")
|
|
95
|
+
html_out = "\n".join(result)
|
|
96
|
+
return {"html": html_out, "input_length": len(markdown), "output_length": len(html_out)}
|
|
97
|
+
|
|
98
|
+
@mcp.tool()
|
|
99
|
+
def generate_toc(markdown: str, max_depth: int = 3, api_key: str = "") -> dict[str, Any]:
|
|
100
|
+
"""Generate a table of contents from Markdown headers."""
|
|
101
|
+
allowed, msg, tier = check_access(api_key)
|
|
102
|
+
if not allowed:
|
|
103
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
104
|
+
if err := _rl(): return err
|
|
105
|
+
|
|
106
|
+
if not _rate_check("generate_toc"):
|
|
107
|
+
return {"error": "Rate limit exceeded (50/day)"}
|
|
108
|
+
headers = []
|
|
109
|
+
for line in markdown.split("\n"):
|
|
110
|
+
m = re.match(r'^(#{1,6})\s+(.+)$', line)
|
|
111
|
+
if m:
|
|
112
|
+
level = len(m.group(1))
|
|
113
|
+
if level <= max_depth:
|
|
114
|
+
text = m.group(2).strip()
|
|
115
|
+
slug = re.sub(r'[^\w\s-]', '', text.lower()).replace(' ', '-')
|
|
116
|
+
headers.append({"level": level, "text": text, "slug": slug})
|
|
117
|
+
toc_lines = []
|
|
118
|
+
for h in headers:
|
|
119
|
+
indent = " " * (h["level"] - 1)
|
|
120
|
+
toc_lines.append(f'{indent}- [{h["text"]}](#{h["slug"]})')
|
|
121
|
+
return {"toc": "\n".join(toc_lines), "headers": headers, "header_count": len(headers)}
|
|
122
|
+
|
|
123
|
+
@mcp.tool()
|
|
124
|
+
def lint_markdown(markdown: str, api_key: str = "") -> dict[str, Any]:
|
|
125
|
+
"""Lint Markdown for common issues."""
|
|
126
|
+
allowed, msg, tier = check_access(api_key)
|
|
127
|
+
if not allowed:
|
|
128
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
129
|
+
if err := _rl(): return err
|
|
130
|
+
|
|
131
|
+
if not _rate_check("lint_markdown"):
|
|
132
|
+
return {"error": "Rate limit exceeded (50/day)"}
|
|
133
|
+
issues = []
|
|
134
|
+
lines = markdown.split("\n")
|
|
135
|
+
for i, line in enumerate(lines, 1):
|
|
136
|
+
if len(line) > 120:
|
|
137
|
+
issues.append({"line": i, "rule": "line-length", "message": f"Line exceeds 120 chars ({len(line)})"})
|
|
138
|
+
if line.rstrip() != line:
|
|
139
|
+
issues.append({"line": i, "rule": "trailing-whitespace", "message": "Trailing whitespace"})
|
|
140
|
+
if re.match(r'^#+[^\s]', line):
|
|
141
|
+
issues.append({"line": i, "rule": "heading-space", "message": "No space after heading marker"})
|
|
142
|
+
if '\t' in line:
|
|
143
|
+
issues.append({"line": i, "rule": "no-tabs", "message": "Tab character found (use spaces)"})
|
|
144
|
+
# Check for multiple blank lines
|
|
145
|
+
for i in range(len(lines) - 1):
|
|
146
|
+
if lines[i].strip() == "" and (i + 1 < len(lines) and lines[i + 1].strip() == ""):
|
|
147
|
+
issues.append({"line": i + 1, "rule": "no-multiple-blanks", "message": "Multiple consecutive blank lines"})
|
|
148
|
+
# Check for broken links
|
|
149
|
+
for i, line in enumerate(lines, 1):
|
|
150
|
+
for m in re.finditer(r'\[([^\]]*)\]\(([^)]*)\)', line):
|
|
151
|
+
if not m.group(2):
|
|
152
|
+
issues.append({"line": i, "rule": "no-empty-links", "message": f"Empty link URL for '{m.group(1)}'"})
|
|
153
|
+
severity = "clean" if not issues else "warning" if len(issues) < 5 else "needs-attention"
|
|
154
|
+
return {"issues": issues, "issue_count": len(issues), "severity": severity, "line_count": len(lines)}
|
|
155
|
+
|
|
156
|
+
@mcp.tool()
|
|
157
|
+
def format_table(headers: str, rows: str, alignment: str = "", api_key: str = "") -> dict[str, Any]:
|
|
158
|
+
"""Format data as a Markdown table. headers: comma-separated. rows: semicolon-separated rows of comma-separated values. alignment: L/C/R per column."""
|
|
159
|
+
allowed, msg, tier = check_access(api_key)
|
|
160
|
+
if not allowed:
|
|
161
|
+
return {"error": msg, "upgrade_url": "https://meok.ai/pricing"}
|
|
162
|
+
if err := _rl(): return err
|
|
163
|
+
|
|
164
|
+
if not _rate_check("format_table"):
|
|
165
|
+
return {"error": "Rate limit exceeded (50/day)"}
|
|
166
|
+
cols = [h.strip() for h in headers.split(",")]
|
|
167
|
+
data_rows = [[c.strip() for c in row.split(",")] for row in rows.split(";") if row.strip()]
|
|
168
|
+
aligns = list(alignment.upper()) if alignment else ["L"] * len(cols)
|
|
169
|
+
while len(aligns) < len(cols):
|
|
170
|
+
aligns.append("L")
|
|
171
|
+
widths = [len(c) for c in cols]
|
|
172
|
+
for row in data_rows:
|
|
173
|
+
for i, cell in enumerate(row):
|
|
174
|
+
if i < len(widths):
|
|
175
|
+
widths[i] = max(widths[i], len(cell))
|
|
176
|
+
def pad(text, width, align):
|
|
177
|
+
if align == "C": return text.center(width)
|
|
178
|
+
if align == "R": return text.rjust(width)
|
|
179
|
+
return text.ljust(width)
|
|
180
|
+
header_line = "| " + " | ".join(pad(c, widths[i], aligns[i]) for i, c in enumerate(cols)) + " |"
|
|
181
|
+
sep_parts = []
|
|
182
|
+
for i, w in enumerate(widths):
|
|
183
|
+
if aligns[i] == "C": sep_parts.append(":" + "-" * (w) + ":")
|
|
184
|
+
elif aligns[i] == "R": sep_parts.append("-" * (w + 1) + ":")
|
|
185
|
+
else: sep_parts.append(":" + "-" * (w + 1))
|
|
186
|
+
sep_line = "| " + " | ".join(sep_parts) + " |"
|
|
187
|
+
row_lines = []
|
|
188
|
+
for row in data_rows:
|
|
189
|
+
padded = []
|
|
190
|
+
for i in range(len(cols)):
|
|
191
|
+
val = row[i] if i < len(row) else ""
|
|
192
|
+
padded.append(pad(val, widths[i], aligns[i]))
|
|
193
|
+
row_lines.append("| " + " | ".join(padded) + " |")
|
|
194
|
+
table = "\n".join([header_line, sep_line] + row_lines)
|
|
195
|
+
return {"table": table, "columns": len(cols), "rows": len(data_rows)}
|
|
196
|
+
|
|
197
|
+
if __name__ == "__main__":
|
|
198
|
+
mcp.run()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: markdown-ai-mcp
|
|
2
|
+
description: 'Markdown Ai MCP server. Tools: convert to html, generate toc, lint markdown.
|
|
3
|
+
Built by MEOK AI Labs.'
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
tools:
|
|
6
|
+
- name: convert_to_html
|
|
7
|
+
description: Convert Markdown to HTML (supports headers, bold, italic, links, code,
|
|
8
|
+
lists).
|
|
9
|
+
parameters:
|
|
10
|
+
- name: markdown
|
|
11
|
+
type: string
|
|
12
|
+
required: true
|
|
13
|
+
- name: generate_toc
|
|
14
|
+
description: Generate a table of contents from Markdown headers.
|
|
15
|
+
parameters:
|
|
16
|
+
- name: markdown
|
|
17
|
+
type: string
|
|
18
|
+
required: true
|
|
19
|
+
- name: max_depth
|
|
20
|
+
type: integer
|
|
21
|
+
required: false
|
|
22
|
+
- name: lint_markdown
|
|
23
|
+
description: Lint Markdown for common issues.
|
|
24
|
+
parameters:
|
|
25
|
+
- name: markdown
|
|
26
|
+
type: string
|
|
27
|
+
required: true
|
|
28
|
+
- name: format_table
|
|
29
|
+
description: 'Format data as a Markdown table. headers: comma-separated. rows: semicolon-separated
|
|
30
|
+
rows of comma-separated values. alignment: L/C/R per column.'
|
|
31
|
+
parameters:
|
|
32
|
+
- name: headers
|
|
33
|
+
type: string
|
|
34
|
+
required: true
|
|
35
|
+
- name: rows
|
|
36
|
+
type: string
|
|
37
|
+
required: true
|
|
38
|
+
- name: alignment
|
|
39
|
+
type: string
|
|
40
|
+
required: false
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import unittest
|
|
4
|
+
|
|
5
|
+
# Ensure shared auth middleware is available
|
|
6
|
+
sys.path.insert(0, os.path.expanduser("~/clawd/meok-labs-engine/shared"))
|
|
7
|
+
os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestMCPImport(unittest.TestCase):
|
|
11
|
+
def test_import_server(self):
|
|
12
|
+
"""Server module must import without errors."""
|
|
13
|
+
import server # noqa: F401
|
|
14
|
+
|
|
15
|
+
def test_mcp_or_server_object_exists(self):
|
|
16
|
+
"""FastMCP servers export 'mcp'; low-level servers export 'server'."""
|
|
17
|
+
import server as srv
|
|
18
|
+
self.assertTrue(
|
|
19
|
+
hasattr(srv, "mcp") or hasattr(srv, "server"),
|
|
20
|
+
"Expected 'mcp' or 'server' object in server.py",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestAuthMiddleware(unittest.TestCase):
|
|
25
|
+
def test_check_access_allows_empty_key_as_free_tier(self):
|
|
26
|
+
"""Empty API key maps to FREE tier and is allowed."""
|
|
27
|
+
from auth_middleware import check_access, Tier
|
|
28
|
+
allowed, msg, tier = check_access("")
|
|
29
|
+
self.assertTrue(allowed)
|
|
30
|
+
self.assertEqual(tier, Tier.FREE)
|
|
31
|
+
self.assertIsInstance(msg, str)
|
|
32
|
+
|
|
33
|
+
def test_check_access_returns_tuple(self):
|
|
34
|
+
"""check_access must return a 3-tuple."""
|
|
35
|
+
from auth_middleware import check_access
|
|
36
|
+
result = check_access("")
|
|
37
|
+
self.assertIsInstance(result, tuple)
|
|
38
|
+
self.assertEqual(len(result), 3)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TestHealthEndpoint(unittest.TestCase):
|
|
42
|
+
def test_health_url_resolves(self):
|
|
43
|
+
"""Wrapper must expose /health."""
|
|
44
|
+
import urllib.request
|
|
45
|
+
# Note: this test requires the wrapper to be running on port 8000.
|
|
46
|
+
# It is skipped in CI unless the server is active.
|
|
47
|
+
try:
|
|
48
|
+
resp = urllib.request.urlopen("http://localhost:8000/health", timeout=2)
|
|
49
|
+
self.assertEqual(resp.status, 200)
|
|
50
|
+
except Exception as e:
|
|
51
|
+
self.skipTest(f"Server not running: {e}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
unittest.main()
|