mcp-cite-fragment 1.0.0
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.
- package/LICENSE +201 -0
- package/README.md +349 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/boundary.d.ts +2 -0
- package/dist/lib/boundary.d.ts.map +1 -0
- package/dist/lib/boundary.js +14 -0
- package/dist/lib/boundary.js.map +1 -0
- package/dist/lib/context/english.d.ts +2 -0
- package/dist/lib/context/english.d.ts.map +1 -0
- package/dist/lib/context/english.js +10 -0
- package/dist/lib/context/english.js.map +1 -0
- package/dist/lib/context/index.d.ts +6 -0
- package/dist/lib/context/index.d.ts.map +1 -0
- package/dist/lib/context/index.js +14 -0
- package/dist/lib/context/index.js.map +1 -0
- package/dist/lib/context/japanese.d.ts +2 -0
- package/dist/lib/context/japanese.d.ts.map +1 -0
- package/dist/lib/context/japanese.js +14 -0
- package/dist/lib/context/japanese.js.map +1 -0
- package/dist/lib/detector.d.ts +3 -0
- package/dist/lib/detector.d.ts.map +1 -0
- package/dist/lib/detector.js +14 -0
- package/dist/lib/detector.js.map +1 -0
- package/dist/lib/extractor.d.ts +2 -0
- package/dist/lib/extractor.d.ts.map +1 -0
- package/dist/lib/extractor.js +17 -0
- package/dist/lib/extractor.js.map +1 -0
- package/dist/lib/fetcher.d.ts +10 -0
- package/dist/lib/fetcher.d.ts.map +1 -0
- package/dist/lib/fetcher.js +144 -0
- package/dist/lib/fetcher.js.map +1 -0
- package/dist/lib/fragment.d.ts +11 -0
- package/dist/lib/fragment.d.ts.map +1 -0
- package/dist/lib/fragment.js +48 -0
- package/dist/lib/fragment.js.map +1 -0
- package/dist/lib/matcher.d.ts +8 -0
- package/dist/lib/matcher.d.ts.map +1 -0
- package/dist/lib/matcher.js +45 -0
- package/dist/lib/matcher.js.map +1 -0
- package/dist/lib/normalizer/english.d.ts +2 -0
- package/dist/lib/normalizer/english.d.ts.map +1 -0
- package/dist/lib/normalizer/english.js +7 -0
- package/dist/lib/normalizer/english.js.map +1 -0
- package/dist/lib/normalizer/index.d.ts +6 -0
- package/dist/lib/normalizer/index.d.ts.map +1 -0
- package/dist/lib/normalizer/index.js +14 -0
- package/dist/lib/normalizer/index.js.map +1 -0
- package/dist/lib/normalizer/japanese.d.ts +2 -0
- package/dist/lib/normalizer/japanese.d.ts.map +1 -0
- package/dist/lib/normalizer/japanese.js +30 -0
- package/dist/lib/normalizer/japanese.js.map +1 -0
- package/dist/lib/pdf-extractor.d.ts +10 -0
- package/dist/lib/pdf-extractor.d.ts.map +1 -0
- package/dist/lib/pdf-extractor.js +19 -0
- package/dist/lib/pdf-extractor.js.map +1 -0
- package/dist/lib/pdf-highlighter.d.ts +8 -0
- package/dist/lib/pdf-highlighter.d.ts.map +1 -0
- package/dist/lib/pdf-highlighter.js +152 -0
- package/dist/lib/pdf-highlighter.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +138 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/check.d.ts +13 -0
- package/dist/tools/check.d.ts.map +1 -0
- package/dist/tools/check.js +60 -0
- package/dist/tools/check.js.map +1 -0
- package/dist/tools/generate.d.ts +3 -0
- package/dist/tools/generate.d.ts.map +1 -0
- package/dist/tools/generate.js +226 -0
- package/dist/tools/generate.js.map +1 -0
- package/dist/tools/highlight.d.ts +22 -0
- package/dist/tools/highlight.d.ts.map +1 -0
- package/dist/tools/highlight.js +87 -0
- package/dist/tools/highlight.js.map +1 -0
- package/dist/tools/verify.d.ts +3 -0
- package/dist/tools/verify.d.ts.map +1 -0
- package/dist/tools/verify.js +150 -0
- package/dist/tools/verify.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +70 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# Cite-Fragment MCP Server
|
|
2
|
+
|
|
3
|
+
AIが生成する調査レポートの主張をソース文書で裏付け、該当箇所に直接ジャンプできる引用リンクを生成するMCPサーバー。
|
|
4
|
+
|
|
5
|
+
W3C [Text Fragments](https://wicg.github.io/scroll-to-text-fragment/) (`#:~:text=`) とPDFページリンク (`#page=N`) を活用し、引用の透明性を確保する。
|
|
6
|
+
|
|
7
|
+
## 解決する課題
|
|
8
|
+
|
|
9
|
+
AIがWeb検索結果を引用する際、ソースURLは提示されるが **ページ内のどの箇所を参照しているかは不明瞭** である。ユーザーが事実確認するには長いページをスクロールして該当箇所を探す必要があり、ファクトチェックのコストが高い。
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Before: [Source](https://example.com/article)
|
|
13
|
+
After: [Source](https://example.com/article#:~:text=引用テキスト)
|
|
14
|
+
クリックすると該当箇所が黄色ハイライトされた状態で表示される
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 提供ツール
|
|
18
|
+
|
|
19
|
+
| ツール | 用途 | 主な利用シーン |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `verify_claims` | 複数の主張を一括でソース文書と照合 | 調査レポートの全主張を一度に検証 |
|
|
22
|
+
| `generate_text_fragment` | 単一の引用テキストからFragment URLを生成 | 個別の引用リンク作成 |
|
|
23
|
+
| `check_fragment_url` | 生成済みFragment URLの有効性検証 | ページ更新後のリンク切れ確認 |
|
|
24
|
+
| `highlight_pdf` | PDF内の該当テキストに黄色ハイライト注釈を追加して保存 | レビュー用のPDF配布 |
|
|
25
|
+
|
|
26
|
+
### `verify_claims` (推奨: 調査タスクのメインツール)
|
|
27
|
+
|
|
28
|
+
複数の主張を一括でソース文書と照合する。同一URLへの複数の主張はページを1回だけ取得する。
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
// 入力
|
|
32
|
+
{
|
|
33
|
+
"claims": [
|
|
34
|
+
{"url": "https://example.com/article", "claim": "actual text from the source", "lang": "en"},
|
|
35
|
+
{"url": "https://example.com/article", "claim": "another claim from same page"},
|
|
36
|
+
{"url": "https://example.jp/doc.pdf", "claim": "PDF内のテキスト", "lang": "ja"}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 出力
|
|
41
|
+
{
|
|
42
|
+
"results": [
|
|
43
|
+
{
|
|
44
|
+
"claim": "actual text from the source",
|
|
45
|
+
"url": "https://example.com/article",
|
|
46
|
+
"status": "verified",
|
|
47
|
+
"fragment_url": "https://example.com/article#:~:text=actual%20text%20from%20the%20source",
|
|
48
|
+
"matched_text": "actual text from the source",
|
|
49
|
+
"surrounding_context": "...preceding text actual text from the source following text..."
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"claim": "another claim from same page",
|
|
53
|
+
"status": "not_found",
|
|
54
|
+
"message": "引用テキストがページ内に見つかりません"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"claim": "PDF内のテキスト",
|
|
58
|
+
"status": "verified",
|
|
59
|
+
"fragment_url": "https://example.jp/doc.pdf#page=5",
|
|
60
|
+
"page_number": 5,
|
|
61
|
+
"matched_text": "PDF内のテキスト",
|
|
62
|
+
"surrounding_context": "...前後100文字の文脈..."
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"summary": { "total": 3, "verified": 2, "not_found": 1, "fetch_failed": 0 }
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**出力フィールドの意味:**
|
|
70
|
+
|
|
71
|
+
| フィールド | 意味 |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `status` | `verified` = ソースに存在, `not_found` = 見つからない, `fetch_failed` = ページ取得失敗 |
|
|
74
|
+
| `matched_text` | ソース上で実際にマッチしたテキスト(正規化前の原文) |
|
|
75
|
+
| `surrounding_context` | マッチ箇所の前後100文字。主張が正確な引用か意訳かを判断するために使用 |
|
|
76
|
+
| `fragment_url` | 該当箇所に直接ジャンプするURL(HTML: `#:~:text=...`, PDF: `#page=N`) |
|
|
77
|
+
|
|
78
|
+
### `generate_text_fragment`
|
|
79
|
+
|
|
80
|
+
単一の引用テキストからFragment URLを生成する。
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
// 入力
|
|
84
|
+
{ "url": "https://example.com/article", "cited_text": "引用テキスト", "lang": "ja" }
|
|
85
|
+
|
|
86
|
+
// 出力 (成功)
|
|
87
|
+
{
|
|
88
|
+
"fragment_url": "https://example.com/article#:~:text=引用テキスト",
|
|
89
|
+
"detected_lang": "ja",
|
|
90
|
+
"is_unique": true,
|
|
91
|
+
"context_used": false,
|
|
92
|
+
"match_count": 1,
|
|
93
|
+
"matched_text": "引用テキスト",
|
|
94
|
+
"surrounding_context": "...前後の文脈..."
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 出力 (エラー)
|
|
98
|
+
{
|
|
99
|
+
"error": "NOT_FOUND",
|
|
100
|
+
"message": "引用テキストがページ内に見つかりません",
|
|
101
|
+
"suggestion": "引用テキストを短縮して再試行してください"
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### `highlight_pdf`
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
// 入力
|
|
109
|
+
{ "url": "https://example.jp/doc.pdf", "cited_text": "ハイライトするテキスト", "lang": "ja" }
|
|
110
|
+
|
|
111
|
+
// 出力
|
|
112
|
+
{
|
|
113
|
+
"file_path": "/tmp/mcp-text-fragment/doc_highlighted.pdf",
|
|
114
|
+
"page_number": 5,
|
|
115
|
+
"match_count": 3,
|
|
116
|
+
"detected_lang": "ja"
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## セットアップ
|
|
121
|
+
|
|
122
|
+
### 前提条件
|
|
123
|
+
|
|
124
|
+
- Node.js 18+ (`Intl.Segmenter` の日本語対応に必要)
|
|
125
|
+
- `qpdf` (暗号化PDFのハイライトに必要。オプション)
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
# macOS
|
|
129
|
+
brew install qpdf
|
|
130
|
+
|
|
131
|
+
# Ubuntu/Debian
|
|
132
|
+
apt-get install qpdf
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Claude Code
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
claude mcp add --transport stdio cite-fragment -- npx -y mcp-cite-fragment
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
これだけで完了。次回の Claude Code セッションから `verify_claims` 等のツールが利用可能になる。
|
|
142
|
+
|
|
143
|
+
**スコープの選択:**
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# ローカル (デフォルト) — このプロジェクトの自分だけ
|
|
147
|
+
claude mcp add --transport stdio cite-fragment -- npx -y mcp-cite-fragment
|
|
148
|
+
|
|
149
|
+
# プロジェクト共有 — .mcp.json に保存、チーム全員が利用可能
|
|
150
|
+
claude mcp add --transport stdio --scope project cite-fragment -- npx -y mcp-cite-fragment
|
|
151
|
+
|
|
152
|
+
# ユーザー全体 — すべてのプロジェクトで利用可能
|
|
153
|
+
claude mcp add --transport stdio --scope user cite-fragment -- npx -y mcp-cite-fragment
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Claude Desktop
|
|
157
|
+
|
|
158
|
+
1. Settings → Developer → Edit Config を開く
|
|
159
|
+
2. `claude_desktop_config.json` に以下を追加:
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"mcpServers": {
|
|
164
|
+
"cite-fragment": {
|
|
165
|
+
"command": "npx",
|
|
166
|
+
"args": ["-y", "mcp-cite-fragment"]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
設定ファイルの場所:
|
|
173
|
+
|
|
174
|
+
| OS | パス |
|
|
175
|
+
|---|---|
|
|
176
|
+
| macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
|
|
177
|
+
| Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
178
|
+
| Linux | `~/.config/Claude/claude_desktop_config.json` |
|
|
179
|
+
|
|
180
|
+
3. Claude Desktop を再起動
|
|
181
|
+
|
|
182
|
+
### 確認
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Claude Code の場合
|
|
186
|
+
claude mcp list
|
|
187
|
+
# cite-fragment: npx -y mcp-cite-fragment - ✓ Connected と表示されれば成功
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### ソースからビルド (開発者向け)
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
git clone https://github.com/ryo63-bot/mcp-cite-fragment
|
|
194
|
+
cd mcp-cite-fragment
|
|
195
|
+
npm install
|
|
196
|
+
npm run build
|
|
197
|
+
|
|
198
|
+
# ローカルビルドを直接指定して接続
|
|
199
|
+
claude mcp add --transport stdio cite-fragment -- node dist/index.js
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Docker
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
docker compose up --build # ビルド&起動
|
|
206
|
+
docker compose up -d # バックグラウンド起動
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Claudeへの指示例 (System Prompt)
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
Web検索で情報を引用する際、以下を実行すること:
|
|
213
|
+
|
|
214
|
+
1. 調査レポートを書き終えたら、全主張を verify_claims で一括検証する
|
|
215
|
+
2. status: "not_found" の主張はソースの原文を確認し、正確な表現に修正する
|
|
216
|
+
3. status: "verified" の主張は fragment_url をMarkdownリンクとして使用する
|
|
217
|
+
4. surrounding_context を確認し、主張が文脈的にも正確か検証する
|
|
218
|
+
5. PDFからの引用が重要な場合、highlight_pdf でハイライト付きPDFを保存する
|
|
219
|
+
|
|
220
|
+
書式例:
|
|
221
|
+
[Source](https://example.com/article#:~:text=引用テキスト)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 対応コンテンツ
|
|
225
|
+
|
|
226
|
+
| コンテンツ種別 | Fragment形式 | 対応状況 |
|
|
227
|
+
|---|---|---|
|
|
228
|
+
| HTML (静的/SSR) | `#:~:text=...` | 対応 |
|
|
229
|
+
| PDF | `#page=N` | 対応 |
|
|
230
|
+
| PDF (暗号化) | `#page=N` + ハイライト | 対応 (qpdf必要) |
|
|
231
|
+
| SPA / CSR (React等) | - | 非対応 (Phase 2) |
|
|
232
|
+
| ログイン必須サイト | - | 非対応 |
|
|
233
|
+
|
|
234
|
+
## 言語対応
|
|
235
|
+
|
|
236
|
+
日本語と英語に最適化。言語は自動検出される(`lang` パラメータで明示指定も可能)。
|
|
237
|
+
|
|
238
|
+
| 処理 | 英語 | 日本語 |
|
|
239
|
+
|---|---|---|
|
|
240
|
+
| 正規化 | 小文字化 + 空白正規化 | 全角/半角統一 + カタカナ→ひらがな |
|
|
241
|
+
| Context抽出 | スペース区切り3語 | `Intl.Segmenter` 6形態素 |
|
|
242
|
+
| 長文閾値 | 60文字 → start,end形式 | 30文字 → start,end形式 |
|
|
243
|
+
| 最小引用長 | 5文字 | 4文字 |
|
|
244
|
+
|
|
245
|
+
## エラーコード
|
|
246
|
+
|
|
247
|
+
| コード | 意味 | 推奨対応 |
|
|
248
|
+
|---|---|---|
|
|
249
|
+
| `NOT_FOUND` | 引用テキストがソースに存在しない | ソースの原文を確認して再試行 |
|
|
250
|
+
| `FETCH_FAILED` | ページの取得に失敗 (403, timeout等) | ソースURLのみ提示 |
|
|
251
|
+
| `INVALID_URL` | https以外のURL | httpsのURLを使用 |
|
|
252
|
+
| `TEXT_TOO_SHORT` | 引用テキストが最小長未満 | より長いテキストを使用 |
|
|
253
|
+
| `ENCODE_TOO_LONG` | Fragment URL が2000文字超 | 引用テキストを短縮 |
|
|
254
|
+
|
|
255
|
+
## アーキテクチャ
|
|
256
|
+
|
|
257
|
+
```
|
|
258
|
+
┌──────────────────────────────────────────────────────────┐
|
|
259
|
+
│ Claude (Claude Code / Claude Desktop) │
|
|
260
|
+
│ │
|
|
261
|
+
│ verify_claims([{url, claim}, ...]) │
|
|
262
|
+
└───────────────────┬──────────────────────────────────────┘
|
|
263
|
+
│ stdio (JSON-RPC)
|
|
264
|
+
┌───────────────────▼──────────────────────────────────────┐
|
|
265
|
+
│ Cite-Fragment MCP Server (Node.js 18+) │
|
|
266
|
+
│ │
|
|
267
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
268
|
+
│ │ Tools │ │
|
|
269
|
+
│ │ verify_claims | generate | check | highlight_pdf │ │
|
|
270
|
+
│ └─────────────────────┬───────────────────────────────┘ │
|
|
271
|
+
│ ↓ │
|
|
272
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
273
|
+
│ │ Core Pipeline │ │
|
|
274
|
+
│ │ │ │
|
|
275
|
+
│ │ fetcher ─→ extractor (HTML) ─→ detector │ │
|
|
276
|
+
│ │ └→ pdf-extractor (PDF) ↓ │ │
|
|
277
|
+
│ │ normalizer (ja|en) │ │
|
|
278
|
+
│ │ ↓ │ │
|
|
279
|
+
│ │ matcher → context │ │
|
|
280
|
+
│ │ ↓ │ │
|
|
281
|
+
│ │ fragment → encoder │ │
|
|
282
|
+
│ │ │ │
|
|
283
|
+
│ │ pdf-highlighter (pdfjs-dist + pdf-lib + qpdf) │ │
|
|
284
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
285
|
+
└───────────────────┬──────────────────────────────────────┘
|
|
286
|
+
│ HTTPS
|
|
287
|
+
┌─────▼─────┐
|
|
288
|
+
│ Web / PDF │
|
|
289
|
+
└───────────┘
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 開発
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
npm run build # TypeScriptコンパイル
|
|
296
|
+
npm run dev # 開発モード (tsx)
|
|
297
|
+
npm test # 全テスト (vitest)
|
|
298
|
+
npm run test:unit # ユニットテストのみ
|
|
299
|
+
npm run test:integ # 統合テストのみ
|
|
300
|
+
npm run lint # ESLint
|
|
301
|
+
npm run format # Prettier
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### ディレクトリ構成
|
|
305
|
+
|
|
306
|
+
```
|
|
307
|
+
src/
|
|
308
|
+
├── index.ts # エントリポイント (stdio接続)
|
|
309
|
+
├── server.ts # MCPサーバー定義 (4ツール登録)
|
|
310
|
+
├── types.ts # 型定義 (Lang, LangConfig, 入出力型)
|
|
311
|
+
├── tools/
|
|
312
|
+
│ ├── generate.ts # generate_text_fragment 実装
|
|
313
|
+
│ ├── verify.ts # verify_claims 実装 (ページキャッシュ付き)
|
|
314
|
+
│ ├── check.ts # check_fragment_url 実装
|
|
315
|
+
│ └── highlight.ts # highlight_pdf 実装
|
|
316
|
+
└── lib/
|
|
317
|
+
├── fetcher.ts # HTML/PDF取得 (タイムアウト・サイズ制限)
|
|
318
|
+
├── extractor.ts # HTML本文抽出 (Readability + linkedom)
|
|
319
|
+
├── pdf-extractor.ts # PDFテキスト抽出 (pdf-parse, ページ単位)
|
|
320
|
+
├── pdf-highlighter.ts # PDFハイライト注釈 (pdfjs-dist + pdf-lib)
|
|
321
|
+
├── detector.ts # 言語自動検出 (ja/en)
|
|
322
|
+
├── matcher.ts # テキスト検索・位置マッピング
|
|
323
|
+
├── fragment.ts # Fragment URL組み立て・エンコード
|
|
324
|
+
├── boundary.ts # ブロック境界検出
|
|
325
|
+
├── normalizer/
|
|
326
|
+
│ ├── index.ts # 言語ディスパッチ
|
|
327
|
+
│ ├── english.ts # 英語正規化 (小文字・空白)
|
|
328
|
+
│ └── japanese.ts # 日本語正規化 (全角半角・カナ変換)
|
|
329
|
+
└── context/
|
|
330
|
+
├── index.ts # 言語ディスパッチ
|
|
331
|
+
├── english.ts # 英語context抽出 (スペース区切り)
|
|
332
|
+
└── japanese.ts # 日本語context抽出 (Intl.Segmenter)
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## ブラウザ対応
|
|
336
|
+
|
|
337
|
+
Text Fragments (`#:~:text=`) のブラウザ対応状況:
|
|
338
|
+
|
|
339
|
+
| ブラウザ | 対応状況 |
|
|
340
|
+
|---|---|
|
|
341
|
+
| Chrome / Edge | 80+ で対応 |
|
|
342
|
+
| Firefox | 131+ で対応 |
|
|
343
|
+
| Safari | 16.1+ で対応 |
|
|
344
|
+
|
|
345
|
+
PDF `#page=N` は主要ブラウザの内蔵PDFビューアすべてで対応。
|
|
346
|
+
|
|
347
|
+
## ライセンス
|
|
348
|
+
|
|
349
|
+
Apache License 2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { createServer } from './server.js';
|
|
4
|
+
async function main() {
|
|
5
|
+
const server = createServer();
|
|
6
|
+
const transport = new StdioServerTransport();
|
|
7
|
+
await server.connect(transport);
|
|
8
|
+
}
|
|
9
|
+
main().catch((err) => {
|
|
10
|
+
console.error('Fatal error:', err);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../src/lib/boundary.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,QAAQ,GAAG,OAAO,GAC5B,MAAM,CAYR"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const BLOCK_BOUNDARY_PATTERN = /\n{2,}|。\s*\n|\.[\s]{2,}/;
|
|
2
|
+
export function truncateAtBlockBoundary(text, direction) {
|
|
3
|
+
if (direction === 'before') {
|
|
4
|
+
const lastBoundary = text.search(new RegExp(`(?:${BLOCK_BOUNDARY_PATTERN.source})[^]*$`));
|
|
5
|
+
return lastBoundary >= 0 ? text.slice(lastBoundary).trimStart() : text;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
const match = text.match(BLOCK_BOUNDARY_PATTERN);
|
|
9
|
+
return match && match.index !== undefined
|
|
10
|
+
? text.slice(0, match.index).trimEnd()
|
|
11
|
+
: text;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../src/lib/boundary.ts"],"names":[],"mappings":"AAAA,MAAM,sBAAsB,GAAG,0BAA0B,CAAC;AAE1D,MAAM,UAAU,uBAAuB,CACrC,IAAY,EACZ,SAA6B;IAE7B,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;QAC3B,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAC9B,IAAI,MAAM,CAAC,MAAM,sBAAsB,CAAC,MAAM,QAAQ,CAAC,CACxD,CAAC;QACF,OAAO,YAAY,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACzE,CAAC;SAAM,CAAC;QACN,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QACjD,OAAO,KAAK,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS;YACvC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE;YACtC,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"english.d.ts","sourceRoot":"","sources":["../../../src/lib/context/english.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,QAAQ,GAAG,OAAO,EAC7B,KAAK,EAAE,MAAM,GACZ,MAAM,CAOR"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function getContextEn(text, direction, count) {
|
|
2
|
+
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
3
|
+
if (direction === 'after') {
|
|
4
|
+
return words.slice(0, count).join(' ');
|
|
5
|
+
}
|
|
6
|
+
else {
|
|
7
|
+
return words.slice(-count).join(' ');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=english.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"english.js","sourceRoot":"","sources":["../../../src/lib/context/english.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,SAA6B,EAC7B,KAAa;IAEb,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvD,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;QAC1B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;SAAM,CAAC;QACN,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Lang } from '../../types.js';
|
|
2
|
+
import { getContextEn } from './english.js';
|
|
3
|
+
import { getContextJa } from './japanese.js';
|
|
4
|
+
export declare function getContext(text: string, direction: 'before' | 'after', count: number, lang: Lang): string;
|
|
5
|
+
export { getContextEn, getContextJa };
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,QAAQ,GAAG,OAAO,EAC7B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,GACT,MAAM,CASR;AAED,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getContextEn } from './english.js';
|
|
2
|
+
import { getContextJa } from './japanese.js';
|
|
3
|
+
export function getContext(text, direction, count, lang) {
|
|
4
|
+
switch (lang) {
|
|
5
|
+
case 'ja':
|
|
6
|
+
return getContextJa(text, direction, count);
|
|
7
|
+
case 'en':
|
|
8
|
+
case 'unknown':
|
|
9
|
+
default:
|
|
10
|
+
return getContextEn(text, direction, count);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export { getContextEn, getContextJa };
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/context/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,UAAU,UAAU,CACxB,IAAY,EACZ,SAA6B,EAC7B,KAAa,EACb,IAAU;IAEV,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,IAAI;YACP,OAAO,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC9C,KAAK,IAAI,CAAC;QACV,KAAK,SAAS,CAAC;QACf;YACE,OAAO,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"japanese.d.ts","sourceRoot":"","sources":["../../../src/lib/context/japanese.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,QAAQ,GAAG,OAAO,EAC7B,KAAK,EAAE,MAAM,GACZ,MAAM,CAYR"}
|