faved-mcp 0.1.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.
- faved_mcp-0.1.0/LICENSE +21 -0
- faved_mcp-0.1.0/PKG-INFO +146 -0
- faved_mcp-0.1.0/README.md +123 -0
- faved_mcp-0.1.0/pyproject.toml +39 -0
- faved_mcp-0.1.0/setup.cfg +4 -0
- faved_mcp-0.1.0/src/faved_mcp/__init__.py +3 -0
- faved_mcp-0.1.0/src/faved_mcp/__main__.py +92 -0
- faved_mcp-0.1.0/src/faved_mcp/client.py +306 -0
- faved_mcp-0.1.0/src/faved_mcp/config.py +66 -0
- faved_mcp-0.1.0/src/faved_mcp/server.py +827 -0
- faved_mcp-0.1.0/src/faved_mcp/setup_cli.py +86 -0
- faved_mcp-0.1.0/src/faved_mcp.egg-info/PKG-INFO +146 -0
- faved_mcp-0.1.0/src/faved_mcp.egg-info/SOURCES.txt +19 -0
- faved_mcp-0.1.0/src/faved_mcp.egg-info/dependency_links.txt +1 -0
- faved_mcp-0.1.0/src/faved_mcp.egg-info/entry_points.txt +2 -0
- faved_mcp-0.1.0/src/faved_mcp.egg-info/requires.txt +6 -0
- faved_mcp-0.1.0/src/faved_mcp.egg-info/top_level.txt +1 -0
- faved_mcp-0.1.0/tests/test_client.py +95 -0
- faved_mcp-0.1.0/tests/test_config.py +45 -0
- faved_mcp-0.1.0/tests/test_setup.py +56 -0
- faved_mcp-0.1.0/tests/test_tools.py +125 -0
faved_mcp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bc1pzzfnxl
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
faved_mcp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: faved-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: MCP server for Faved, the open-source bookmark manager
|
|
5
|
+
Author: bc1pzzfnxl
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/bc1pzzfnxl/faved-mcp
|
|
8
|
+
Project-URL: Repository, https://github.com/bc1pzzfnxl/faved-mcp
|
|
9
|
+
Project-URL: Issues, https://github.com/bc1pzzfnxl/faved-mcp/issues
|
|
10
|
+
Keywords: mcp,faved,bookmarks,tags,agents
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: mcp>=2.0
|
|
18
|
+
Requires-Dist: httpx>=0.27
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
21
|
+
Requires-Dist: respx>=0.21; extra == "dev"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# faved-mcp
|
|
25
|
+
|
|
26
|
+
An MCP server for [Faved](https://github.com/denho/faved), the open-source bookmark manager.
|
|
27
|
+
|
|
28
|
+
It exposes Faved's bookmarks, hierarchical tags (folders), metadata, imports and exports as MCP tools, so any MCP client (Claude Desktop, Cursor, Hermes, custom agents) can read and organize a collection without screen-scraping or direct SQLite access.
|
|
29
|
+
|
|
30
|
+
- Works against any Faved instance: self-hosted or cloud.
|
|
31
|
+
- API-only: no database coupling, no Faved core changes.
|
|
32
|
+
- Read-only by default; write tools are opt-in.
|
|
33
|
+
- Ships both as a Python package and as a Docker layer on top of the official Faved image.
|
|
34
|
+
|
|
35
|
+
## Status
|
|
36
|
+
|
|
37
|
+
v0.1.0: 18 tools, API-only, read-only by default. Tests cover the client and every tool group; the stdio and HTTP transports are verified end to end.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install faved-mcp
|
|
43
|
+
faved-mcp setup
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`setup` asks for your Faved URL, the username and password you already use, checks the
|
|
47
|
+
login, and writes `~/.config/faved-mcp/config.json` (mode 600). Then point your MCP
|
|
48
|
+
client at `faved-mcp`; no other configuration is needed.
|
|
49
|
+
|
|
50
|
+
Environment variables override the file, for Docker and CI:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
export FAVED_URL=https://faved.example.com
|
|
54
|
+
export FAVED_USERNAME=alice
|
|
55
|
+
export FAVED_PASSWORD=...
|
|
56
|
+
faved-mcp
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
HTTP mode, for containers and remote clients:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
export FAVED_MCP_TOKEN=$(openssl rand -hex 32)
|
|
63
|
+
faved-mcp --transport http --host 0.0.0.0 --port 8090
|
|
64
|
+
# MCP endpoint: http://host:8090/mcp (Authorization: Bearer $FAVED_MCP_TOKEN)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
| Variable | Default | Meaning |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `FAVED_URL` | `http://localhost` | Base URL of the Faved instance |
|
|
72
|
+
| `FAVED_USERNAME` | — | Faved account used by the server |
|
|
73
|
+
| `FAVED_PASSWORD` | — | Its password |
|
|
74
|
+
| `FAVED_MCP_TRANSPORT` | `stdio` | `stdio` or `http` |
|
|
75
|
+
| `FAVED_MCP_HOST` | `127.0.0.1` | HTTP bind address |
|
|
76
|
+
| `FAVED_MCP_PORT` | `8090` | HTTP port |
|
|
77
|
+
| `FAVED_MCP_TOKEN` | — | Bearer token required in HTTP mode |
|
|
78
|
+
| `FAVED_MCP_ENABLE_WRITE` | `false` | Enable mutating tools |
|
|
79
|
+
| `FAVED_MCP_ALLOW_LOCAL_PATHS` | `false` | Allow `import_bookmarks` to read a server-side file path |
|
|
80
|
+
| `FAVED_MCP_TIMEOUT` | `15` | Upstream timeout, seconds |
|
|
81
|
+
|
|
82
|
+
`faved-mcp setup` stores your existing Faved login in the config file; environment variables take precedence. A `reader` account gives read-only access at the API level; an `owner` account is required for write tools. A separate service account is optional, not mandatory. Never expose the HTTP transport publicly without `FAVED_MCP_TOKEN`.
|
|
83
|
+
|
|
84
|
+
## Docker
|
|
85
|
+
|
|
86
|
+
Build the layer that adds the MCP server beside Apache in the official Faved image:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
docker build --load -t faved-mcp:0.1.0 .
|
|
90
|
+
# or keep your pinned/patched base:
|
|
91
|
+
docker build --load --build-arg BASE_IMAGE=faved-app:2.10.1-ro1 -t faved-mcp:0.1.0 .
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
On a BuildKit docker-container builder, `--load` is required or the image stays in the build cache.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
docker run --rm -p 8080:80 -p 8090:8090 \
|
|
98
|
+
-e FAVED_USERNAME=mcp -e FAVED_PASSWORD=... \
|
|
99
|
+
-e FAVED_MCP_TOKEN=$(openssl rand -hex 32) \
|
|
100
|
+
-e FAVED_MCP_ENABLE_WRITE=false \
|
|
101
|
+
-v faved-data:/var/www/html/storage \
|
|
102
|
+
faved-mcp:0.1.0
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
A compose example is in [docker-compose.example.yml](docker-compose.example.yml).
|
|
106
|
+
|
|
107
|
+
The container runs `supervisord` with Apache and `faved-mcp` (HTTP, port 8090, `/mcp`). `FAVED_URL` defaults to `http://127.0.0.1`, so the MCP server talks to the Faved instance in the same container. Publish 8090 only on an internal network; exposing it is the operator's decision.
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python3 -m venv .venv
|
|
113
|
+
.venv/bin/pip install -e '.[dev]'
|
|
114
|
+
PYTHONPATH=src .venv/bin/pytest -q
|
|
115
|
+
.venv/bin/python scripts/smoke_stdio.py # stub Faved + MCP stdio handshake
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Client configuration
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"mcpServers": {
|
|
123
|
+
"faved": {
|
|
124
|
+
"type": "http",
|
|
125
|
+
"url": "https://faved-mcp.example.com/mcp",
|
|
126
|
+
"headers": { "Authorization": "Bearer <FAVED_MCP_TOKEN>" }
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Authentication, the dedicated Faved account and WAN exposure are explained in [docs/DEPLOY.md](docs/DEPLOY.md).
|
|
133
|
+
|
|
134
|
+
## Tools
|
|
135
|
+
|
|
136
|
+
See [docs/TOOLS.md](docs/TOOLS.md) for the full contract. Summary:
|
|
137
|
+
|
|
138
|
+
Read: `faved_status`, `list_bookmarks`, `get_bookmark`, `search_bookmarks`, `list_tags`, `get_tag`, `collection_stats`, `find_duplicates`, `fetch_url_metadata`.
|
|
139
|
+
|
|
140
|
+
Write (opt-in): `add_bookmark`, `update_bookmark`, `delete_bookmarks`, `tag_bookmarks`, `create_tag`, `update_tag`, `delete_tag`.
|
|
141
|
+
|
|
142
|
+
Import/export: `import_bookmarks`, `export_bookmarks`.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT, same as Faved.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# faved-mcp
|
|
2
|
+
|
|
3
|
+
An MCP server for [Faved](https://github.com/denho/faved), the open-source bookmark manager.
|
|
4
|
+
|
|
5
|
+
It exposes Faved's bookmarks, hierarchical tags (folders), metadata, imports and exports as MCP tools, so any MCP client (Claude Desktop, Cursor, Hermes, custom agents) can read and organize a collection without screen-scraping or direct SQLite access.
|
|
6
|
+
|
|
7
|
+
- Works against any Faved instance: self-hosted or cloud.
|
|
8
|
+
- API-only: no database coupling, no Faved core changes.
|
|
9
|
+
- Read-only by default; write tools are opt-in.
|
|
10
|
+
- Ships both as a Python package and as a Docker layer on top of the official Faved image.
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
14
|
+
v0.1.0: 18 tools, API-only, read-only by default. Tests cover the client and every tool group; the stdio and HTTP transports are verified end to end.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install faved-mcp
|
|
20
|
+
faved-mcp setup
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`setup` asks for your Faved URL, the username and password you already use, checks the
|
|
24
|
+
login, and writes `~/.config/faved-mcp/config.json` (mode 600). Then point your MCP
|
|
25
|
+
client at `faved-mcp`; no other configuration is needed.
|
|
26
|
+
|
|
27
|
+
Environment variables override the file, for Docker and CI:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
export FAVED_URL=https://faved.example.com
|
|
31
|
+
export FAVED_USERNAME=alice
|
|
32
|
+
export FAVED_PASSWORD=...
|
|
33
|
+
faved-mcp
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
HTTP mode, for containers and remote clients:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
export FAVED_MCP_TOKEN=$(openssl rand -hex 32)
|
|
40
|
+
faved-mcp --transport http --host 0.0.0.0 --port 8090
|
|
41
|
+
# MCP endpoint: http://host:8090/mcp (Authorization: Bearer $FAVED_MCP_TOKEN)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
| Variable | Default | Meaning |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `FAVED_URL` | `http://localhost` | Base URL of the Faved instance |
|
|
49
|
+
| `FAVED_USERNAME` | — | Faved account used by the server |
|
|
50
|
+
| `FAVED_PASSWORD` | — | Its password |
|
|
51
|
+
| `FAVED_MCP_TRANSPORT` | `stdio` | `stdio` or `http` |
|
|
52
|
+
| `FAVED_MCP_HOST` | `127.0.0.1` | HTTP bind address |
|
|
53
|
+
| `FAVED_MCP_PORT` | `8090` | HTTP port |
|
|
54
|
+
| `FAVED_MCP_TOKEN` | — | Bearer token required in HTTP mode |
|
|
55
|
+
| `FAVED_MCP_ENABLE_WRITE` | `false` | Enable mutating tools |
|
|
56
|
+
| `FAVED_MCP_ALLOW_LOCAL_PATHS` | `false` | Allow `import_bookmarks` to read a server-side file path |
|
|
57
|
+
| `FAVED_MCP_TIMEOUT` | `15` | Upstream timeout, seconds |
|
|
58
|
+
|
|
59
|
+
`faved-mcp setup` stores your existing Faved login in the config file; environment variables take precedence. A `reader` account gives read-only access at the API level; an `owner` account is required for write tools. A separate service account is optional, not mandatory. Never expose the HTTP transport publicly without `FAVED_MCP_TOKEN`.
|
|
60
|
+
|
|
61
|
+
## Docker
|
|
62
|
+
|
|
63
|
+
Build the layer that adds the MCP server beside Apache in the official Faved image:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
docker build --load -t faved-mcp:0.1.0 .
|
|
67
|
+
# or keep your pinned/patched base:
|
|
68
|
+
docker build --load --build-arg BASE_IMAGE=faved-app:2.10.1-ro1 -t faved-mcp:0.1.0 .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
On a BuildKit docker-container builder, `--load` is required or the image stays in the build cache.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
docker run --rm -p 8080:80 -p 8090:8090 \
|
|
75
|
+
-e FAVED_USERNAME=mcp -e FAVED_PASSWORD=... \
|
|
76
|
+
-e FAVED_MCP_TOKEN=$(openssl rand -hex 32) \
|
|
77
|
+
-e FAVED_MCP_ENABLE_WRITE=false \
|
|
78
|
+
-v faved-data:/var/www/html/storage \
|
|
79
|
+
faved-mcp:0.1.0
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
A compose example is in [docker-compose.example.yml](docker-compose.example.yml).
|
|
83
|
+
|
|
84
|
+
The container runs `supervisord` with Apache and `faved-mcp` (HTTP, port 8090, `/mcp`). `FAVED_URL` defaults to `http://127.0.0.1`, so the MCP server talks to the Faved instance in the same container. Publish 8090 only on an internal network; exposing it is the operator's decision.
|
|
85
|
+
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python3 -m venv .venv
|
|
90
|
+
.venv/bin/pip install -e '.[dev]'
|
|
91
|
+
PYTHONPATH=src .venv/bin/pytest -q
|
|
92
|
+
.venv/bin/python scripts/smoke_stdio.py # stub Faved + MCP stdio handshake
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Client configuration
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"mcpServers": {
|
|
100
|
+
"faved": {
|
|
101
|
+
"type": "http",
|
|
102
|
+
"url": "https://faved-mcp.example.com/mcp",
|
|
103
|
+
"headers": { "Authorization": "Bearer <FAVED_MCP_TOKEN>" }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Authentication, the dedicated Faved account and WAN exposure are explained in [docs/DEPLOY.md](docs/DEPLOY.md).
|
|
110
|
+
|
|
111
|
+
## Tools
|
|
112
|
+
|
|
113
|
+
See [docs/TOOLS.md](docs/TOOLS.md) for the full contract. Summary:
|
|
114
|
+
|
|
115
|
+
Read: `faved_status`, `list_bookmarks`, `get_bookmark`, `search_bookmarks`, `list_tags`, `get_tag`, `collection_stats`, `find_duplicates`, `fetch_url_metadata`.
|
|
116
|
+
|
|
117
|
+
Write (opt-in): `add_bookmark`, `update_bookmark`, `delete_bookmarks`, `tag_bookmarks`, `create_tag`, `update_tag`, `delete_tag`.
|
|
118
|
+
|
|
119
|
+
Import/export: `import_bookmarks`, `export_bookmarks`.
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT, same as Faved.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "faved-mcp"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "MCP server for Faved, the open-source bookmark manager"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "bc1pzzfnxl" }]
|
|
13
|
+
keywords = ["mcp", "faved", "bookmarks", "tags", "agents"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"mcp>=2.0",
|
|
21
|
+
"httpx>=0.27",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/bc1pzzfnxl/faved-mcp"
|
|
26
|
+
Repository = "https://github.com/bc1pzzfnxl/faved-mcp"
|
|
27
|
+
Issues = "https://github.com/bc1pzzfnxl/faved-mcp/issues"
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["pytest>=8", "respx>=0.21"]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
faved-mcp = "faved_mcp.__main__:main"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
|
37
|
+
|
|
38
|
+
[tool.pytest.ini_options]
|
|
39
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Console entry point: setup wizard, stdio for local clients, streamable HTTP for containers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import hmac
|
|
8
|
+
import sys
|
|
9
|
+
from dataclasses import replace
|
|
10
|
+
|
|
11
|
+
from starlette.middleware.base import BaseHTTPMiddleware
|
|
12
|
+
from starlette.responses import JSONResponse
|
|
13
|
+
|
|
14
|
+
from . import __version__
|
|
15
|
+
from .config import Config, config_path
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class BearerAuth(BaseHTTPMiddleware):
|
|
19
|
+
def __init__(self, app, token: str):
|
|
20
|
+
super().__init__(app)
|
|
21
|
+
self.token = token
|
|
22
|
+
|
|
23
|
+
async def dispatch(self, request, call_next):
|
|
24
|
+
if request.url.path == "/health":
|
|
25
|
+
return JSONResponse({"ok": True})
|
|
26
|
+
header = request.headers.get("authorization", "")
|
|
27
|
+
expected = f"Bearer {self.token}"
|
|
28
|
+
if not hmac.compare_digest(header, expected):
|
|
29
|
+
return JSONResponse({"ok": False, "code": "unauthorized", "message": "Bearer token required"}, status_code=401)
|
|
30
|
+
return await call_next(request)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _parser() -> argparse.ArgumentParser:
|
|
34
|
+
parser = argparse.ArgumentParser(
|
|
35
|
+
prog="faved-mcp",
|
|
36
|
+
description="MCP server for Faved. Run without arguments to start the stdio server.",
|
|
37
|
+
)
|
|
38
|
+
parser.add_argument("command", nargs="?", default="serve", choices=["serve", "setup"], help="serve (default) or setup")
|
|
39
|
+
parser.add_argument("--transport", choices=["stdio", "http", "streamable-http"], help="override FAVED_MCP_TRANSPORT")
|
|
40
|
+
parser.add_argument("--host", help="override FAVED_MCP_HOST")
|
|
41
|
+
parser.add_argument("--port", type=int, help="override FAVED_MCP_PORT")
|
|
42
|
+
parser.add_argument("--version", action="version", version=f"faved-mcp {__version__}")
|
|
43
|
+
return parser
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main() -> None:
|
|
47
|
+
args = _parser().parse_args()
|
|
48
|
+
|
|
49
|
+
if args.command == "setup":
|
|
50
|
+
from .setup_cli import run_setup
|
|
51
|
+
|
|
52
|
+
raise SystemExit(run_setup())
|
|
53
|
+
|
|
54
|
+
config = Config.from_env()
|
|
55
|
+
if args.transport:
|
|
56
|
+
config = replace(config, transport=args.transport.lower())
|
|
57
|
+
if args.host:
|
|
58
|
+
config = replace(config, host=args.host)
|
|
59
|
+
if args.port:
|
|
60
|
+
config = replace(config, port=args.port)
|
|
61
|
+
|
|
62
|
+
if not config.credentials_configured():
|
|
63
|
+
print(
|
|
64
|
+
"No Faved credentials configured.\n"
|
|
65
|
+
"Run `faved-mcp setup` once, or set FAVED_URL / FAVED_USERNAME / FAVED_PASSWORD.\n"
|
|
66
|
+
f"Config file: {config_path()}",
|
|
67
|
+
file=sys.stderr,
|
|
68
|
+
)
|
|
69
|
+
raise SystemExit(2)
|
|
70
|
+
|
|
71
|
+
from .server import mcp
|
|
72
|
+
|
|
73
|
+
transport = config.transport
|
|
74
|
+
if transport == "stdio":
|
|
75
|
+
asyncio.run(mcp.run_stdio_async())
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
if transport not in {"http", "streamable-http"}:
|
|
79
|
+
sys.exit(f"Unsupported transport '{transport}'. Use stdio or http.")
|
|
80
|
+
|
|
81
|
+
if not config.token:
|
|
82
|
+
sys.exit("FAVED_MCP_TOKEN is required for the HTTP transport.")
|
|
83
|
+
|
|
84
|
+
import uvicorn
|
|
85
|
+
|
|
86
|
+
app = mcp.streamable_http_app(host=config.host)
|
|
87
|
+
app.add_middleware(BearerAuth, token=config.token)
|
|
88
|
+
uvicorn.run(app, host=config.host, port=config.port)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
if __name__ == "__main__":
|
|
92
|
+
main()
|