@funmary/mcp 0.0.0-reserved → 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/README.md +44 -0
- package/dist/LICENSE-APACHE-2.0 +201 -0
- package/dist/LICENSE-BSD-3-CLAUSE +28 -0
- package/dist/bin.js +18 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.js +2 -0
- package/dist/stdio-CHgt2MDi.js +689 -0
- package/package.json +35 -11
- package/index.js +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @funmary/mcp
|
|
2
|
+
|
|
3
|
+
[Funmary](https://github.com/funmary-app/funmary) の MCP サーバーです。手元のパソコンで動かして、Claude Desktop などから、自分の時間割、休講、予定、バスの時刻表を読み書きできます。Funmary は、公立はこだて未来大学の学生向けの、非公式のアプリです。
|
|
4
|
+
|
|
5
|
+
## 使い方
|
|
6
|
+
|
|
7
|
+
Funmary の設定画面で、個人用のアクセストークンを発行し、クライアントの設定に書きます。
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
{
|
|
11
|
+
"mcpServers": {
|
|
12
|
+
"funmary": {
|
|
13
|
+
"command": "npx",
|
|
14
|
+
"args": ["-y", "@funmary/mcp"],
|
|
15
|
+
"env": {
|
|
16
|
+
"FUNMARY_URL": "https://funmary.example.com",
|
|
17
|
+
"FUNMARY_TOKEN": "fmy_..."
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
- `FUNMARY_URL`: 使っている Funmary のサーバーの URL。既定値は持ちません
|
|
25
|
+
- `FUNMARY_TOKEN`: 個人用のアクセストークン。トークンに許した範囲 (`read:lessons`、`write:events` など) の道具だけが出ます。書き込みの範囲は、必要なときだけ許してください
|
|
26
|
+
|
|
27
|
+
道具の定義は、Funmary のサーバーの `/mcp` と共有しています。サーバーの `/mcp` に、OAuth で直接つなぐこともできます。
|
|
28
|
+
|
|
29
|
+
## ライブラリとして
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { createFunmaryMcpServer, createClientData } from '@funmary/mcp';
|
|
33
|
+
import { createFunmaryClient } from '@funmary/client';
|
|
34
|
+
|
|
35
|
+
const client = createFunmaryClient({ baseURL, token });
|
|
36
|
+
const server = createFunmaryMcpServer({
|
|
37
|
+
data: createClientData(client),
|
|
38
|
+
scopes: (await client.me()).scopes,
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## ライセンス
|
|
43
|
+
|
|
44
|
+
BSD-3-Clause または Apache-2.0 (好きな方を選べます)。
|
|
@@ -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 2026 [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.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, otoneko. a.k.a. marron., oto-lab, and Funmary (funmary-app)
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as runStdioServer } from "./stdio-CHgt2MDi.js";
|
|
3
|
+
//#region src/bin.ts
|
|
4
|
+
const baseURL = process.env["FUNMARY_URL"];
|
|
5
|
+
const token = process.env["FUNMARY_TOKEN"];
|
|
6
|
+
if (!baseURL || !token) {
|
|
7
|
+
console.error("環境変数 FUNMARY_URL (Funmary のサーバーの URL) と FUNMARY_TOKEN (個人用のアクセストークン) を設定してください");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
runStdioServer({
|
|
11
|
+
baseURL,
|
|
12
|
+
token
|
|
13
|
+
}).catch((error) => {
|
|
14
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
15
|
+
process.exit(1);
|
|
16
|
+
});
|
|
17
|
+
//#endregion
|
|
18
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { FunmaryClient } from "@funmary/client";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
//#region src/data.d.ts
|
|
5
|
+
/** 公開 API と同じ形の JSON */
|
|
6
|
+
type Json = object;
|
|
7
|
+
interface DateRange {
|
|
8
|
+
readonly start: string;
|
|
9
|
+
readonly end: string;
|
|
10
|
+
}
|
|
11
|
+
/** 科目の指し方。年度とシラバスの番号か、名前 (年度を省くと、今年度) */
|
|
12
|
+
type CourseRef = {
|
|
13
|
+
readonly academicYear: number;
|
|
14
|
+
readonly syllabusId: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly academicYear?: number | undefined;
|
|
18
|
+
};
|
|
19
|
+
interface FunmaryData {
|
|
20
|
+
timetable(range: DateRange): Promise<Json>;
|
|
21
|
+
week(query: {
|
|
22
|
+
date?: string | undefined;
|
|
23
|
+
}): Promise<Json>;
|
|
24
|
+
nextLesson(): Promise<Json>;
|
|
25
|
+
periods(): Promise<readonly Json[]>;
|
|
26
|
+
courses(): Promise<readonly Json[]>;
|
|
27
|
+
academicCalendar(query: {
|
|
28
|
+
year?: number | undefined;
|
|
29
|
+
}): Promise<Json>;
|
|
30
|
+
events(range: DateRange): Promise<readonly Json[]>;
|
|
31
|
+
event(id: number): Promise<Json | null>;
|
|
32
|
+
status(): Promise<Json>;
|
|
33
|
+
searchSubjects(query: {
|
|
34
|
+
q?: string | undefined;
|
|
35
|
+
year?: number | undefined;
|
|
36
|
+
term?: string | undefined;
|
|
37
|
+
}): Promise<Json>;
|
|
38
|
+
subjectSessions(ref: {
|
|
39
|
+
year: number;
|
|
40
|
+
syllabusId: string;
|
|
41
|
+
}): Promise<Json | null>;
|
|
42
|
+
subject(ref: {
|
|
43
|
+
year: number;
|
|
44
|
+
syllabusId: string;
|
|
45
|
+
}): Promise<Json | null>;
|
|
46
|
+
notifications(query: {
|
|
47
|
+
limit?: number | undefined;
|
|
48
|
+
afterId?: number | undefined;
|
|
49
|
+
}): Promise<readonly Json[]>;
|
|
50
|
+
busStops(): Promise<Json | null>;
|
|
51
|
+
busStopTimetable(stopId: string, generation?: number): Promise<Json | null>;
|
|
52
|
+
busLeg(query: {
|
|
53
|
+
stopId: string;
|
|
54
|
+
direction: 'toUniversity' | 'fromUniversity';
|
|
55
|
+
day?: 'weekday' | 'holiday' | undefined;
|
|
56
|
+
limit?: number | undefined;
|
|
57
|
+
}): Promise<Json | null>;
|
|
58
|
+
busNext(query: {
|
|
59
|
+
stopId?: string | undefined;
|
|
60
|
+
limit?: number | undefined;
|
|
61
|
+
}): Promise<Json | null>;
|
|
62
|
+
createEvent(body: unknown): Promise<Json>;
|
|
63
|
+
replaceEvent(id: number, body: unknown): Promise<Json>;
|
|
64
|
+
deleteEvent(id: number): Promise<void>;
|
|
65
|
+
registerCourse(ref: CourseRef): Promise<Json>;
|
|
66
|
+
unregisterCourse(ref: CourseRef): Promise<Json>;
|
|
67
|
+
setPersonalSlot(ref: CourseRef, slot: {
|
|
68
|
+
weekday: number;
|
|
69
|
+
period: number;
|
|
70
|
+
room?: string | null | undefined;
|
|
71
|
+
}): Promise<Json>;
|
|
72
|
+
removePersonalSlot(ref: CourseRef, slot: {
|
|
73
|
+
weekday: number;
|
|
74
|
+
period: number;
|
|
75
|
+
}): Promise<Json>;
|
|
76
|
+
setAbbreviation(ref: CourseRef, abbreviation: string): Promise<Json>;
|
|
77
|
+
markNotificationRead(id: number): Promise<Json>;
|
|
78
|
+
markAllNotificationsRead(): Promise<Json>;
|
|
79
|
+
}
|
|
80
|
+
/** 書き込みや読み取りの失敗。文は、そのまま、利用者 (と AI) に見せる */
|
|
81
|
+
export declare class FunmaryToolFailure extends Error {
|
|
82
|
+
constructor(message: string);
|
|
83
|
+
}
|
|
84
|
+
/** 名前が複数の科目に当たったときの、候補つきの文 (道具の答えと、手元の MCP の両方で同じにする) */
|
|
85
|
+
export declare function ambiguousMessage(error: string, candidates: readonly {
|
|
86
|
+
academicYear: number;
|
|
87
|
+
syllabusId: string;
|
|
88
|
+
name: string;
|
|
89
|
+
}[]): string;
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/client-data.d.ts
|
|
92
|
+
export declare function createClientData(client: FunmaryClient): FunmaryData;
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/tools.d.ts
|
|
95
|
+
interface ToolContext {
|
|
96
|
+
readonly data: FunmaryData;
|
|
97
|
+
/** いまの時刻 (省くと「今日」を決めるのに使う)。テストで差し替える */
|
|
98
|
+
readonly now: () => Date;
|
|
99
|
+
}
|
|
100
|
+
type ToolOutput = {
|
|
101
|
+
readonly kind: 'json';
|
|
102
|
+
readonly value: object;
|
|
103
|
+
} | {
|
|
104
|
+
readonly kind: 'error';
|
|
105
|
+
readonly message: string;
|
|
106
|
+
};
|
|
107
|
+
interface ToolAnnotations {
|
|
108
|
+
readonly readOnlyHint: boolean;
|
|
109
|
+
readonly destructiveHint?: boolean;
|
|
110
|
+
readonly idempotentHint?: boolean;
|
|
111
|
+
}
|
|
112
|
+
interface ToolDefinition<Shape extends z.ZodRawShape = z.ZodRawShape> {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
/** アクセストークンの範囲 (read:lessons など)。この範囲を持つときだけ、道具を出す */
|
|
115
|
+
readonly scope: string;
|
|
116
|
+
readonly description: string;
|
|
117
|
+
readonly inputSchema?: Shape;
|
|
118
|
+
readonly annotations: ToolAnnotations;
|
|
119
|
+
run(context: ToolContext, args: z.infer<z.ZodObject<Shape>>): Promise<ToolOutput>;
|
|
120
|
+
}
|
|
121
|
+
/** すべての道具。出す順は、読み取り、書き込みの順 */
|
|
122
|
+
export declare const TOOLS: readonly ToolDefinition[];
|
|
123
|
+
/** 道具の処理で起きた失敗を、利用者に見せる文にする。想定外の例外は、そのまま投げる */
|
|
124
|
+
export declare function failureMessage(caught: unknown): string | null;
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/server.d.ts
|
|
127
|
+
interface RegisterToolsOptions {
|
|
128
|
+
readonly data: FunmaryData;
|
|
129
|
+
/** トークンに許された範囲。この範囲の道具だけを出す */
|
|
130
|
+
readonly scopes: readonly string[];
|
|
131
|
+
/** 範囲があっても、出さない道具を決める (例: バスの機能を使わないサーバーで、バスの道具を出さない) */
|
|
132
|
+
readonly enabled?: (tool: ToolDefinition) => boolean;
|
|
133
|
+
readonly now?: () => Date;
|
|
134
|
+
}
|
|
135
|
+
/** 範囲に合う道具を、サーバーに登録する。登録した道具の名前を返す */
|
|
136
|
+
export declare function registerTools(server: McpServer, options: RegisterToolsOptions): string[];
|
|
137
|
+
interface CreateMcpServerOptions extends RegisterToolsOptions {
|
|
138
|
+
readonly name?: string;
|
|
139
|
+
readonly version?: string;
|
|
140
|
+
readonly icons?: readonly {
|
|
141
|
+
src: string;
|
|
142
|
+
mimeType?: string;
|
|
143
|
+
sizes?: string[];
|
|
144
|
+
theme?: 'light' | 'dark';
|
|
145
|
+
}[];
|
|
146
|
+
}
|
|
147
|
+
/** 道具を登録した MCP サーバーを作る */
|
|
148
|
+
export declare function createFunmaryMcpServer(options: CreateMcpServerOptions): McpServer;
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/stdio.d.ts
|
|
151
|
+
interface StdioOptions {
|
|
152
|
+
/** Funmary のサーバーの URL (既定値は持たない) */
|
|
153
|
+
readonly baseURL: string;
|
|
154
|
+
/** 設定画面で発行した、個人用のアクセストークン */
|
|
155
|
+
readonly token: string;
|
|
156
|
+
readonly version?: string;
|
|
157
|
+
}
|
|
158
|
+
/** サーバーを起動して、標準入出力に結ぶ。トークンが使えなければ、理由の分かる文で、例外にする */
|
|
159
|
+
export declare function runStdioServer(options: StdioOptions): Promise<void>;
|
|
160
|
+
//#endregion
|
|
161
|
+
export type { CourseRef, CreateMcpServerOptions, DateRange, FunmaryData, Json, RegisterToolsOptions, StdioOptions, ToolAnnotations, ToolContext, ToolDefinition, ToolOutput };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as failureMessage, c as ambiguousMessage, i as TOOLS, n as createFunmaryMcpServer, o as createClientData, r as registerTools, s as FunmaryToolFailure, t as runStdioServer } from "./stdio-CHgt2MDi.js";
|
|
2
|
+
export { FunmaryToolFailure, TOOLS, ambiguousMessage, createClientData, createFunmaryMcpServer, failureMessage, registerTools, runStdioServer };
|
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import { FunmaryApiError, createFunmaryClient } from "@funmary/client";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
//#region src/data.ts
|
|
6
|
+
/** 書き込みや読み取りの失敗。文は、そのまま、利用者 (と AI) に見せる */
|
|
7
|
+
var FunmaryToolFailure = class extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "FunmaryToolFailure";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/** 名前が複数の科目に当たったときの、候補つきの文 (道具の答えと、手元の MCP の両方で同じにする) */
|
|
14
|
+
function ambiguousMessage(error, candidates) {
|
|
15
|
+
return `${error}: ${candidates.map((c) => `${c.academicYear} ${c.syllabusId} ${c.name}`).join(" / ")}`;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/client-data.ts
|
|
19
|
+
/** 404 を「見つからない」(null) にする。ほかの誤りは、そのまま投げる */
|
|
20
|
+
async function orNull(read) {
|
|
21
|
+
try {
|
|
22
|
+
return await read;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error instanceof FunmaryApiError && error.status === 404) return null;
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function createClientData(client) {
|
|
29
|
+
/**
|
|
30
|
+
* 書き込みの API は、年度とシラバスの番号で科目を指す。名前で指されたときは、科目の検索で、番号に直す。
|
|
31
|
+
* 完全に一致する科目が 1 つならそれを、なければ部分一致が 1 つならそれを選び、複数なら、候補つきで断る
|
|
32
|
+
*/
|
|
33
|
+
async function resolve(ref) {
|
|
34
|
+
if ("syllabusId" in ref) return {
|
|
35
|
+
year: ref.academicYear,
|
|
36
|
+
syllabusId: ref.syllabusId
|
|
37
|
+
};
|
|
38
|
+
const needle = ref.name.trim().toLowerCase();
|
|
39
|
+
const found = (await client.subjects.search({
|
|
40
|
+
q: ref.name,
|
|
41
|
+
year: ref.academicYear
|
|
42
|
+
})).subjects;
|
|
43
|
+
const exact = found.filter((subject) => subject.name.trim().toLowerCase() === needle);
|
|
44
|
+
const matched = exact.length > 0 ? exact : found;
|
|
45
|
+
const [only] = matched;
|
|
46
|
+
if (matched.length === 1 && only) return {
|
|
47
|
+
year: only.academicYear,
|
|
48
|
+
syllabusId: only.syllabusId
|
|
49
|
+
};
|
|
50
|
+
if (matched.length === 0) throw new FunmaryToolFailure("科目が見つかりません");
|
|
51
|
+
throw new FunmaryToolFailure(ambiguousMessage(`「${ref.name}」に当たる科目が ${matched.length} 件あります。年度とシラバスの番号で指してください`, matched.toSorted((a, b) => a.syllabusId.localeCompare(b.syllabusId)).slice(0, 10)));
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
timetable: (range) => client.timetable(range),
|
|
55
|
+
week: (query) => client.week(query.date === void 0 ? {} : { date: query.date }),
|
|
56
|
+
nextLesson: () => client.nextLesson(),
|
|
57
|
+
periods: () => client.periods(),
|
|
58
|
+
courses: () => client.courses.list(),
|
|
59
|
+
academicCalendar: (query) => client.academicCalendar(query.year === void 0 ? {} : { year: query.year }),
|
|
60
|
+
events: (range) => client.events.list(range),
|
|
61
|
+
event: (id) => orNull(client.events.get(id)),
|
|
62
|
+
status: () => client.status(),
|
|
63
|
+
searchSubjects: (query) => client.subjects.search(query),
|
|
64
|
+
subjectSessions: (ref) => orNull(client.subjects.sessions(ref)),
|
|
65
|
+
subject: (ref) => orNull(client.subjects.get(ref)),
|
|
66
|
+
notifications: (query) => client.notifications.list(query),
|
|
67
|
+
busStops: () => orNull(client.bus.stops()),
|
|
68
|
+
busStopTimetable: (stopId, generation) => orNull(client.bus.stop(stopId, generation === void 0 ? {} : { generation })),
|
|
69
|
+
busLeg: (query) => orNull(client.bus.legs({
|
|
70
|
+
stopId: query.stopId,
|
|
71
|
+
direction: query.direction,
|
|
72
|
+
...query.day === void 0 ? {} : { day: query.day },
|
|
73
|
+
...query.limit === void 0 ? {} : { limit: query.limit }
|
|
74
|
+
})),
|
|
75
|
+
busNext: (query) => orNull(client.bus.next({
|
|
76
|
+
...query.stopId === void 0 ? {} : { stopId: query.stopId },
|
|
77
|
+
...query.limit === void 0 ? {} : { limit: query.limit }
|
|
78
|
+
})),
|
|
79
|
+
createEvent: (body) => client.events.create(body),
|
|
80
|
+
replaceEvent: (id, body) => client.events.replace(id, body),
|
|
81
|
+
deleteEvent: (id) => client.events.delete(id).then(() => void 0),
|
|
82
|
+
registerCourse: (ref) => client.courses.register("syllabusId" in ref ? {
|
|
83
|
+
academicYear: ref.academicYear,
|
|
84
|
+
syllabusId: ref.syllabusId
|
|
85
|
+
} : {
|
|
86
|
+
name: ref.name,
|
|
87
|
+
...ref.academicYear === void 0 ? {} : { academicYear: ref.academicYear }
|
|
88
|
+
}),
|
|
89
|
+
unregisterCourse: async (ref) => client.courses.unregister(await resolve(ref)),
|
|
90
|
+
setPersonalSlot: async (ref, slot) => client.courses.setPersonalSlot(await resolve(ref), {
|
|
91
|
+
weekday: slot.weekday,
|
|
92
|
+
period: slot.period,
|
|
93
|
+
room: slot.room ?? null
|
|
94
|
+
}),
|
|
95
|
+
removePersonalSlot: async (ref, slot) => client.courses.removePersonalSlot(await resolve(ref), slot),
|
|
96
|
+
setAbbreviation: async (ref, abbreviation) => client.courses.setAbbreviation(await resolve(ref), abbreviation),
|
|
97
|
+
markNotificationRead: (id) => client.notifications.markRead(id),
|
|
98
|
+
markAllNotificationsRead: () => client.notifications.markAllRead()
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/tools.ts
|
|
103
|
+
const json = (value) => ({
|
|
104
|
+
kind: "json",
|
|
105
|
+
value
|
|
106
|
+
});
|
|
107
|
+
const error = (message) => ({
|
|
108
|
+
kind: "error",
|
|
109
|
+
message
|
|
110
|
+
});
|
|
111
|
+
const orNotFound = (value) => json(value ?? { error: "not_found" });
|
|
112
|
+
/** 日本時間の今日の日付 (YYYY-MM-DD) */
|
|
113
|
+
const todayJst = (now) => new Date(now.getTime() + 324e5).toISOString().slice(0, 10);
|
|
114
|
+
const READ = { readOnlyHint: true };
|
|
115
|
+
function define(tool) {
|
|
116
|
+
return tool;
|
|
117
|
+
}
|
|
118
|
+
const readLessons = [
|
|
119
|
+
define({
|
|
120
|
+
name: "get_lessons",
|
|
121
|
+
scope: "read:lessons",
|
|
122
|
+
description: "日付 (YYYY-MM-DD、日本時間) か期間の授業を、開始と終了の時刻つきで返す (日付を省くと今日)。days に、振替授業日 (その日に行う授業の曜日)、全学の休講日、祝日が入る。status は normal (変更なし)、cancelled (休講)、makeup (補講)、roomChanged (教室変更)。room が null なら教室は分からず、roomIsTentative が true なら補講の教室を、ふだんの教室で仮に出している",
|
|
123
|
+
inputSchema: {
|
|
124
|
+
start: z.string().optional(),
|
|
125
|
+
end: z.string().optional()
|
|
126
|
+
},
|
|
127
|
+
annotations: READ,
|
|
128
|
+
async run({ data, now }, { start, end }) {
|
|
129
|
+
const today = todayJst(now());
|
|
130
|
+
return json(await data.timetable({
|
|
131
|
+
start: start ?? today,
|
|
132
|
+
end: end ?? start ?? today
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
}),
|
|
136
|
+
define({
|
|
137
|
+
name: "get_week",
|
|
138
|
+
scope: "read:lessons",
|
|
139
|
+
description: "date (YYYY-MM-DD、日本時間。省くと今日) を含む週 (月曜から日曜) の、曜日と時限の格子。授業のない時限も cells に入る (lessons が空)。振替授業日などは note に入る",
|
|
140
|
+
inputSchema: { date: z.string().optional() },
|
|
141
|
+
annotations: READ,
|
|
142
|
+
async run({ data, now }, { date }) {
|
|
143
|
+
return json(await data.week({ date: date ?? todayJst(now()) }));
|
|
144
|
+
}
|
|
145
|
+
}),
|
|
146
|
+
define({
|
|
147
|
+
name: "get_next_lesson",
|
|
148
|
+
scope: "read:lessons",
|
|
149
|
+
description: "今の時刻から見た、次の授業を返す。授業中ならその授業 (inProgress が true)。休講の授業は飛ばし、14 日先まで見て、なければ next が null",
|
|
150
|
+
annotations: READ,
|
|
151
|
+
async run({ data }) {
|
|
152
|
+
return json(await data.nextLesson());
|
|
153
|
+
}
|
|
154
|
+
}),
|
|
155
|
+
define({
|
|
156
|
+
name: "get_periods",
|
|
157
|
+
scope: "read:lessons",
|
|
158
|
+
description: "時限ごとの開始と終了の時刻 (日本時間)",
|
|
159
|
+
annotations: READ,
|
|
160
|
+
async run({ data }) {
|
|
161
|
+
return json({ periods: await data.periods() });
|
|
162
|
+
}
|
|
163
|
+
}),
|
|
164
|
+
define({
|
|
165
|
+
name: "list_courses",
|
|
166
|
+
scope: "read:lessons",
|
|
167
|
+
description: "履修登録した科目と、その曜日 (1 が月曜から 7 が日曜) と時限",
|
|
168
|
+
annotations: READ,
|
|
169
|
+
async run({ data }) {
|
|
170
|
+
return json({ courses: await data.courses() });
|
|
171
|
+
}
|
|
172
|
+
}),
|
|
173
|
+
define({
|
|
174
|
+
name: "get_academic_calendar",
|
|
175
|
+
scope: "read:lessons",
|
|
176
|
+
description: "年度の学期の期間と、その年度の祝日、全学の休講日、振替授業日を返す (年度を省くと今日が属する年度)",
|
|
177
|
+
inputSchema: { year: z.number().optional() },
|
|
178
|
+
annotations: READ,
|
|
179
|
+
async run({ data }, { year }) {
|
|
180
|
+
return json(await data.academicCalendar({ year }));
|
|
181
|
+
}
|
|
182
|
+
}),
|
|
183
|
+
define({
|
|
184
|
+
name: "list_events",
|
|
185
|
+
scope: "read:lessons",
|
|
186
|
+
description: "日付 (YYYY-MM-DD、日本時間) の範囲の、自分の予定と、時間割に加えたほかの人の予定 (繰り返しは回ごとに展開)。日付を省くと今日",
|
|
187
|
+
inputSchema: {
|
|
188
|
+
start: z.string().optional(),
|
|
189
|
+
end: z.string().optional()
|
|
190
|
+
},
|
|
191
|
+
annotations: READ,
|
|
192
|
+
async run({ data, now }, { start, end }) {
|
|
193
|
+
const today = todayJst(now());
|
|
194
|
+
return json({ events: await data.events({
|
|
195
|
+
start: start ?? today,
|
|
196
|
+
end: end ?? start ?? today
|
|
197
|
+
}) });
|
|
198
|
+
}
|
|
199
|
+
}),
|
|
200
|
+
define({
|
|
201
|
+
name: "get_event",
|
|
202
|
+
scope: "read:lessons",
|
|
203
|
+
description: "自分の予定を 1 件、update_event に送り直せる形で返す。繰り返しや除く日も入る。ほかの人の予定は、見つからないことにする",
|
|
204
|
+
inputSchema: { id: z.number().describe("予定の id (list_events の eventId)") },
|
|
205
|
+
annotations: READ,
|
|
206
|
+
async run({ data }, { id }) {
|
|
207
|
+
const event = await data.event(id);
|
|
208
|
+
return event ? json(event) : error("予定が見つかりません");
|
|
209
|
+
}
|
|
210
|
+
}),
|
|
211
|
+
define({
|
|
212
|
+
name: "get_data_status",
|
|
213
|
+
scope: "read:lessons",
|
|
214
|
+
description: "休講や教室の変更のデータが新しいか。stale が true のときは、反映が遅れているかもしれないので、授業の答えに添える",
|
|
215
|
+
annotations: READ,
|
|
216
|
+
async run({ data }) {
|
|
217
|
+
return json(await data.status());
|
|
218
|
+
}
|
|
219
|
+
}),
|
|
220
|
+
define({
|
|
221
|
+
name: "search_subjects",
|
|
222
|
+
scope: "read:lessons",
|
|
223
|
+
description: "年度 (省けば今年度) の科目を、名前、教員、授業コードで探す。公開の科目だけを 50 件まで返す。term は spring、fall など",
|
|
224
|
+
inputSchema: {
|
|
225
|
+
q: z.string().max(100).optional(),
|
|
226
|
+
year: z.number().optional(),
|
|
227
|
+
term: z.string().optional()
|
|
228
|
+
},
|
|
229
|
+
annotations: READ,
|
|
230
|
+
async run({ data }, query) {
|
|
231
|
+
return json(await data.searchSubjects(query));
|
|
232
|
+
}
|
|
233
|
+
}),
|
|
234
|
+
define({
|
|
235
|
+
name: "get_subject_sessions",
|
|
236
|
+
scope: "read:lessons",
|
|
237
|
+
description: "科目のその年度の全授業日 (時刻、教室、休講、補講、教室変更を反映)。sequence は休講を除いた通し番号で、シラバスの第 n 回とは限らない",
|
|
238
|
+
inputSchema: {
|
|
239
|
+
year: z.number(),
|
|
240
|
+
syllabusId: z.string()
|
|
241
|
+
},
|
|
242
|
+
annotations: READ,
|
|
243
|
+
async run({ data }, ref) {
|
|
244
|
+
return orNotFound(await data.subjectSessions(ref));
|
|
245
|
+
}
|
|
246
|
+
}),
|
|
247
|
+
define({
|
|
248
|
+
name: "get_subject",
|
|
249
|
+
scope: "read:lessons",
|
|
250
|
+
description: "授業の詳細を返す",
|
|
251
|
+
inputSchema: {
|
|
252
|
+
year: z.number(),
|
|
253
|
+
syllabusId: z.string()
|
|
254
|
+
},
|
|
255
|
+
annotations: READ,
|
|
256
|
+
async run({ data }, ref) {
|
|
257
|
+
return orNotFound(await data.subject(ref));
|
|
258
|
+
}
|
|
259
|
+
}),
|
|
260
|
+
define({
|
|
261
|
+
name: "list_changes",
|
|
262
|
+
scope: "read:changes",
|
|
263
|
+
description: "日付 (YYYY-MM-DD、日本時間) の範囲の休講、補講、教室変更を返す。days に、その期間の振替授業日、全学の休講日、祝日も入る",
|
|
264
|
+
inputSchema: {
|
|
265
|
+
start: z.string(),
|
|
266
|
+
end: z.string()
|
|
267
|
+
},
|
|
268
|
+
annotations: READ,
|
|
269
|
+
async run({ data }, { start, end }) {
|
|
270
|
+
const { lessons, days } = await data.timetable({
|
|
271
|
+
start,
|
|
272
|
+
end
|
|
273
|
+
});
|
|
274
|
+
return json({
|
|
275
|
+
changes: lessons.filter((lesson) => lesson.status !== "normal"),
|
|
276
|
+
days
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}),
|
|
280
|
+
define({
|
|
281
|
+
name: "list_notifications",
|
|
282
|
+
scope: "read:notifications",
|
|
283
|
+
description: "通知欄 (休講、補講、教室変更などの知らせ) を、新しい順に返す。前回読んだ最大の id を afterId に渡すと、それより新しいものだけを返すので、定期的な確認に使える",
|
|
284
|
+
inputSchema: {
|
|
285
|
+
limit: z.number().optional(),
|
|
286
|
+
afterId: z.number().optional()
|
|
287
|
+
},
|
|
288
|
+
annotations: READ,
|
|
289
|
+
async run({ data }, query) {
|
|
290
|
+
return json({ notifications: await data.notifications(query) });
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
];
|
|
294
|
+
const readTransit = [
|
|
295
|
+
define({
|
|
296
|
+
name: "list_bus_stops",
|
|
297
|
+
scope: "read:transit",
|
|
298
|
+
description: "バスの停留所と、時刻表の版 (ダイヤ改正ごと) の一覧。highlighted が true の停留所は、既定で強調する停留所 (未来大、亀田支所前)。まだ取り込んでいなければ stops が空",
|
|
299
|
+
annotations: READ,
|
|
300
|
+
async run({ data }) {
|
|
301
|
+
return json(await data.busStops() ?? { error: "not_available" });
|
|
302
|
+
}
|
|
303
|
+
}),
|
|
304
|
+
define({
|
|
305
|
+
name: "get_bus_stop_timetable",
|
|
306
|
+
scope: "read:transit",
|
|
307
|
+
description: "1 つの停留所の発車表。のりばと曜日の区分 (weekday は平日、holiday は土曜、日曜、祝日) ごとに分かれ、発車の time は HH:MM (日本時間、24 時以降は 24:10 のように書く)。notes に印の意味がある。generation (8 桁の版のコード) を省くと、今日に有効な版",
|
|
308
|
+
inputSchema: {
|
|
309
|
+
stopId: z.string(),
|
|
310
|
+
generation: z.number().optional()
|
|
311
|
+
},
|
|
312
|
+
annotations: READ,
|
|
313
|
+
async run({ data }, { stopId, generation }) {
|
|
314
|
+
return orNotFound(await data.busStopTimetable(stopId, generation));
|
|
315
|
+
}
|
|
316
|
+
}),
|
|
317
|
+
define({
|
|
318
|
+
name: "get_bus_leg",
|
|
319
|
+
scope: "read:transit",
|
|
320
|
+
description: "「A から未来大へ」「未来大から A へ」のバスの発車。stopId は、未来大を通る任意の停留所 A (list_bus_stops で探す)。direction は toUniversity (A から未来大) か fromUniversity (未来大から A)。departures はその日の区分の全部、upcoming はこれからの発車。向きは、時刻表の経由と行き先の文字から決めるので、経由に書かれない停留所を通る便は、出ないことがある。day (weekday か holiday) を省くと今日の区分",
|
|
321
|
+
inputSchema: {
|
|
322
|
+
stopId: z.string(),
|
|
323
|
+
direction: z.enum(["toUniversity", "fromUniversity"]),
|
|
324
|
+
day: z.enum(["weekday", "holiday"]).optional(),
|
|
325
|
+
limit: z.number().optional()
|
|
326
|
+
},
|
|
327
|
+
annotations: READ,
|
|
328
|
+
async run({ data }, query) {
|
|
329
|
+
return orNotFound(await data.busLeg(query));
|
|
330
|
+
}
|
|
331
|
+
}),
|
|
332
|
+
define({
|
|
333
|
+
name: "get_next_buses",
|
|
334
|
+
scope: "read:transit",
|
|
335
|
+
description: "今から先のバスの発車を、停留所ごとに近い順に返す (土曜、日曜、祝日は休日の発車表)。stopId を省くと、強調する停留所 (未来大、亀田支所前)。limit は停留所ごとの件数 (既定 3)。minutesUntil は発車までの分",
|
|
336
|
+
inputSchema: {
|
|
337
|
+
stopId: z.string().optional(),
|
|
338
|
+
limit: z.number().optional()
|
|
339
|
+
},
|
|
340
|
+
annotations: READ,
|
|
341
|
+
async run({ data }, query) {
|
|
342
|
+
return orNotFound(await data.busNext(query));
|
|
343
|
+
}
|
|
344
|
+
})
|
|
345
|
+
];
|
|
346
|
+
/** 予定の項目。足すときと直すときで同じ (REST の本文と同じ形) */
|
|
347
|
+
const eventShape = {
|
|
348
|
+
title: z.string().describe("予定の名前 (100 文字まで)"),
|
|
349
|
+
location: z.string().nullable().optional().describe("場所 (100 文字まで)"),
|
|
350
|
+
notes: z.string().nullable().optional().describe("メモ (1000 文字まで)"),
|
|
351
|
+
startDate: z.string().describe("開始日 (YYYY-MM-DD)"),
|
|
352
|
+
endDate: z.string().nullable().optional().describe("終了日 (YYYY-MM-DD)。省けば開始日と同じ。数日にわたる予定は終日だけ"),
|
|
353
|
+
time: z.discriminatedUnion("kind", [
|
|
354
|
+
z.object({ kind: z.literal("allDay") }),
|
|
355
|
+
z.object({
|
|
356
|
+
kind: z.literal("time"),
|
|
357
|
+
start: z.string().describe("HH:MM (日本時間)"),
|
|
358
|
+
end: z.string().describe("HH:MM。始まりより後")
|
|
359
|
+
}),
|
|
360
|
+
z.object({
|
|
361
|
+
kind: z.literal("period"),
|
|
362
|
+
from: z.number().describe("始まりの時限 (1 から 6)"),
|
|
363
|
+
to: z.number().describe("終わりの時限 (始まり以上、6 まで)")
|
|
364
|
+
})
|
|
365
|
+
]).describe("終日、時刻、時限のどれか"),
|
|
366
|
+
repeat: z.object({
|
|
367
|
+
freq: z.enum([
|
|
368
|
+
"daily",
|
|
369
|
+
"weekly",
|
|
370
|
+
"monthly",
|
|
371
|
+
"yearly"
|
|
372
|
+
]),
|
|
373
|
+
interval: z.number().optional().describe("間隔 (1 から 99)。省けば 1"),
|
|
374
|
+
weekdays: z.array(z.number()).optional().describe("weekly のとき。曜日 (月曜が 1、日曜が 7)。省けば開始日の曜日"),
|
|
375
|
+
monthly: z.enum([
|
|
376
|
+
"day",
|
|
377
|
+
"nth",
|
|
378
|
+
"last"
|
|
379
|
+
]).optional().describe("monthly のとき。day は毎月の同じ日、nth は第何曜日、last は最終週の曜日"),
|
|
380
|
+
end: z.discriminatedUnion("kind", [
|
|
381
|
+
z.object({ kind: z.literal("never") }),
|
|
382
|
+
z.object({
|
|
383
|
+
kind: z.literal("until"),
|
|
384
|
+
date: z.string()
|
|
385
|
+
}),
|
|
386
|
+
z.object({
|
|
387
|
+
kind: z.literal("count"),
|
|
388
|
+
count: z.number()
|
|
389
|
+
})
|
|
390
|
+
]).optional().describe("省けば、終わりなし")
|
|
391
|
+
}).nullable().optional().describe("繰り返さないなら省くか null"),
|
|
392
|
+
excludedDates: z.array(z.string()).optional().describe("繰り返しから除く日 (YYYY-MM-DD。始まりの日で数える)")
|
|
393
|
+
};
|
|
394
|
+
/** 履修の道具が、科目を指すための項目 */
|
|
395
|
+
const courseRefShape = {
|
|
396
|
+
academicYear: z.number().optional().describe("年度 (例: 2026)。name で指すときは省ける"),
|
|
397
|
+
syllabusId: z.string().optional().describe("シラバスの番号 (授業コード)"),
|
|
398
|
+
name: z.string().optional().describe("科目名。syllabusId を省くときに使う")
|
|
399
|
+
};
|
|
400
|
+
/** 引数から、科目の指し方を決める。足りなければ、利用者に伝える文を返す */
|
|
401
|
+
function refOf(args) {
|
|
402
|
+
if (args.syllabusId !== void 0) return args.academicYear === void 0 ? { error: "syllabusId で指すときは、academicYear (年度) も必要です" } : { ref: {
|
|
403
|
+
academicYear: args.academicYear,
|
|
404
|
+
syllabusId: args.syllabusId
|
|
405
|
+
} };
|
|
406
|
+
if (args.name !== void 0) return { ref: {
|
|
407
|
+
name: args.name,
|
|
408
|
+
academicYear: args.academicYear
|
|
409
|
+
} };
|
|
410
|
+
return { error: "科目を、academicYear と syllabusId か、name で指してください" };
|
|
411
|
+
}
|
|
412
|
+
const slotShape = {
|
|
413
|
+
weekday: z.number().describe("曜日 (1 が月曜から 6 が土曜)"),
|
|
414
|
+
period: z.number().describe("時限 (1 から 6)")
|
|
415
|
+
};
|
|
416
|
+
const writeEvents = [
|
|
417
|
+
define({
|
|
418
|
+
name: "create_event",
|
|
419
|
+
scope: "write:events",
|
|
420
|
+
description: "自分の予定を足す。公開範囲は決められず、常に非公開で足す。足した予定 (id つき) を返す。1 分あたり 20 回まで",
|
|
421
|
+
inputSchema: eventShape,
|
|
422
|
+
annotations: {
|
|
423
|
+
readOnlyHint: false,
|
|
424
|
+
destructiveHint: false,
|
|
425
|
+
idempotentHint: false
|
|
426
|
+
},
|
|
427
|
+
async run({ data }, args) {
|
|
428
|
+
return json(await data.createEvent(args));
|
|
429
|
+
}
|
|
430
|
+
}),
|
|
431
|
+
define({
|
|
432
|
+
name: "update_event",
|
|
433
|
+
scope: "write:events",
|
|
434
|
+
description: "自分の予定を、送った内容に置き換える (送らなかった項目は、空になる)。先に get_event で今の内容を読み、変える項目だけを書き換えて送る。公開範囲は変わらない",
|
|
435
|
+
inputSchema: {
|
|
436
|
+
id: z.number().describe("予定の id"),
|
|
437
|
+
...eventShape
|
|
438
|
+
},
|
|
439
|
+
annotations: {
|
|
440
|
+
readOnlyHint: false,
|
|
441
|
+
destructiveHint: true,
|
|
442
|
+
idempotentHint: true
|
|
443
|
+
},
|
|
444
|
+
async run({ data }, { id, ...rest }) {
|
|
445
|
+
return json(await data.replaceEvent(id, rest));
|
|
446
|
+
}
|
|
447
|
+
}),
|
|
448
|
+
define({
|
|
449
|
+
name: "delete_event",
|
|
450
|
+
scope: "write:events",
|
|
451
|
+
description: "自分の予定を消す。元には戻せないので、消す前に、利用者に確かめる",
|
|
452
|
+
inputSchema: { id: z.number().describe("予定の id") },
|
|
453
|
+
annotations: {
|
|
454
|
+
readOnlyHint: false,
|
|
455
|
+
destructiveHint: true,
|
|
456
|
+
idempotentHint: true
|
|
457
|
+
},
|
|
458
|
+
async run({ data }, { id }) {
|
|
459
|
+
await data.deleteEvent(id);
|
|
460
|
+
return json({
|
|
461
|
+
deleted: true,
|
|
462
|
+
id
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
];
|
|
467
|
+
const writeCourses = [
|
|
468
|
+
define({
|
|
469
|
+
name: "register_course",
|
|
470
|
+
scope: "write:courses",
|
|
471
|
+
description: "履修登録する。科目は、academicYear (年度) と syllabusId (シラバスの番号) か、name (科目名。年度を省くと今年度) で指す。name が複数の科目に当たったら、登録せず候補を返すので、利用者に確かめて、番号で指し直す。登録済みなら、何も変えずに今の状態を返す",
|
|
472
|
+
inputSchema: courseRefShape,
|
|
473
|
+
annotations: {
|
|
474
|
+
readOnlyHint: false,
|
|
475
|
+
destructiveHint: false,
|
|
476
|
+
idempotentHint: true
|
|
477
|
+
},
|
|
478
|
+
async run({ data }, args) {
|
|
479
|
+
const target = refOf(args);
|
|
480
|
+
return "error" in target ? error(target.error) : json(await data.registerCourse(target.ref));
|
|
481
|
+
}
|
|
482
|
+
}),
|
|
483
|
+
define({
|
|
484
|
+
name: "unregister_course",
|
|
485
|
+
scope: "write:courses",
|
|
486
|
+
description: "履修登録を取り消す。自分だけの曜日と時限と略称は残るので、登録し直せば元に戻る。取り消す前に、利用者に確かめる",
|
|
487
|
+
inputSchema: courseRefShape,
|
|
488
|
+
annotations: {
|
|
489
|
+
readOnlyHint: false,
|
|
490
|
+
destructiveHint: true,
|
|
491
|
+
idempotentHint: true
|
|
492
|
+
},
|
|
493
|
+
async run({ data }, args) {
|
|
494
|
+
const target = refOf(args);
|
|
495
|
+
return "error" in target ? error(target.error) : json(await data.unregisterCourse(target.ref));
|
|
496
|
+
}
|
|
497
|
+
}),
|
|
498
|
+
define({
|
|
499
|
+
name: "set_personal_slot",
|
|
500
|
+
scope: "write:courses",
|
|
501
|
+
description: "自分だけに使う曜日と時限を足す (同じ曜日と時限があれば、教室を上書きする)。ほかの利用者の時間割には効かない。履修登録した科目だけ。共有の枠は、ここからは書き込めない",
|
|
502
|
+
inputSchema: {
|
|
503
|
+
...courseRefShape,
|
|
504
|
+
...slotShape,
|
|
505
|
+
room: z.string().nullable().optional().describe("教室 (100 文字まで)。省くと空")
|
|
506
|
+
},
|
|
507
|
+
annotations: {
|
|
508
|
+
readOnlyHint: false,
|
|
509
|
+
destructiveHint: false,
|
|
510
|
+
idempotentHint: true
|
|
511
|
+
},
|
|
512
|
+
async run({ data }, { weekday, period, room, ...refArgs }) {
|
|
513
|
+
const target = refOf(refArgs);
|
|
514
|
+
return "error" in target ? error(target.error) : json(await data.setPersonalSlot(target.ref, {
|
|
515
|
+
weekday,
|
|
516
|
+
period,
|
|
517
|
+
room
|
|
518
|
+
}));
|
|
519
|
+
}
|
|
520
|
+
}),
|
|
521
|
+
define({
|
|
522
|
+
name: "remove_personal_slot",
|
|
523
|
+
scope: "write:courses",
|
|
524
|
+
description: "自分だけの曜日と時限を消す",
|
|
525
|
+
inputSchema: {
|
|
526
|
+
...courseRefShape,
|
|
527
|
+
...slotShape
|
|
528
|
+
},
|
|
529
|
+
annotations: {
|
|
530
|
+
readOnlyHint: false,
|
|
531
|
+
destructiveHint: true,
|
|
532
|
+
idempotentHint: true
|
|
533
|
+
},
|
|
534
|
+
async run({ data }, { weekday, period, ...refArgs }) {
|
|
535
|
+
const target = refOf(refArgs);
|
|
536
|
+
return "error" in target ? error(target.error) : json(await data.removePersonalSlot(target.ref, {
|
|
537
|
+
weekday,
|
|
538
|
+
period
|
|
539
|
+
}));
|
|
540
|
+
}
|
|
541
|
+
}),
|
|
542
|
+
define({
|
|
543
|
+
name: "set_subject_abbreviation",
|
|
544
|
+
scope: "write:courses",
|
|
545
|
+
description: "時間割のセルに出す、自分だけの略称を保存する (100 文字まで)。空にすると、正式名称を使う指定になる",
|
|
546
|
+
inputSchema: {
|
|
547
|
+
...courseRefShape,
|
|
548
|
+
abbreviation: z.string().describe("略称。空文字で、正式名称に戻す")
|
|
549
|
+
},
|
|
550
|
+
annotations: {
|
|
551
|
+
readOnlyHint: false,
|
|
552
|
+
destructiveHint: false,
|
|
553
|
+
idempotentHint: true
|
|
554
|
+
},
|
|
555
|
+
async run({ data }, { abbreviation, ...refArgs }) {
|
|
556
|
+
const target = refOf(refArgs);
|
|
557
|
+
return "error" in target ? error(target.error) : json(await data.setAbbreviation(target.ref, abbreviation));
|
|
558
|
+
}
|
|
559
|
+
})
|
|
560
|
+
];
|
|
561
|
+
const writeNotifications = [define({
|
|
562
|
+
name: "mark_notification_read",
|
|
563
|
+
scope: "write:notifications",
|
|
564
|
+
description: "通知を 1 件、既読にして返す",
|
|
565
|
+
inputSchema: { id: z.number().describe("通知の id") },
|
|
566
|
+
annotations: {
|
|
567
|
+
readOnlyHint: false,
|
|
568
|
+
destructiveHint: false,
|
|
569
|
+
idempotentHint: true
|
|
570
|
+
},
|
|
571
|
+
async run({ data }, { id }) {
|
|
572
|
+
return json(await data.markNotificationRead(id));
|
|
573
|
+
}
|
|
574
|
+
}), define({
|
|
575
|
+
name: "mark_all_notifications_read",
|
|
576
|
+
scope: "write:notifications",
|
|
577
|
+
description: "未読の通知をすべて既読にし、既読にした件数を返す",
|
|
578
|
+
inputSchema: {},
|
|
579
|
+
annotations: {
|
|
580
|
+
readOnlyHint: false,
|
|
581
|
+
destructiveHint: false,
|
|
582
|
+
idempotentHint: true
|
|
583
|
+
},
|
|
584
|
+
async run({ data }) {
|
|
585
|
+
return json(await data.markAllNotificationsRead());
|
|
586
|
+
}
|
|
587
|
+
})];
|
|
588
|
+
/** すべての道具。出す順は、読み取り、書き込みの順 */
|
|
589
|
+
const TOOLS = [
|
|
590
|
+
...readLessons,
|
|
591
|
+
...readTransit,
|
|
592
|
+
...writeEvents,
|
|
593
|
+
...writeCourses,
|
|
594
|
+
...writeNotifications
|
|
595
|
+
];
|
|
596
|
+
/** 道具の処理で起きた失敗を、利用者に見せる文にする。想定外の例外は、そのまま投げる */
|
|
597
|
+
function failureMessage(caught) {
|
|
598
|
+
if (caught instanceof FunmaryToolFailure) return caught.message;
|
|
599
|
+
if (typeof caught === "object" && caught !== null && "name" in caught) {
|
|
600
|
+
const named = caught;
|
|
601
|
+
if (named.name === "FunmaryApiError" && typeof named.message === "string") {
|
|
602
|
+
const body = named.body;
|
|
603
|
+
if (named.code === "ambiguous" && Array.isArray(body?.candidates)) return ambiguousMessage(named.message, body.candidates);
|
|
604
|
+
return named.message;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region src/server.ts
|
|
611
|
+
function toResult(output) {
|
|
612
|
+
if (output.kind === "error") return {
|
|
613
|
+
isError: true,
|
|
614
|
+
content: [{
|
|
615
|
+
type: "text",
|
|
616
|
+
text: output.message
|
|
617
|
+
}]
|
|
618
|
+
};
|
|
619
|
+
return {
|
|
620
|
+
content: [{
|
|
621
|
+
type: "text",
|
|
622
|
+
text: JSON.stringify(output.value)
|
|
623
|
+
}],
|
|
624
|
+
structuredContent: output.value
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
/** 範囲に合う道具を、サーバーに登録する。登録した道具の名前を返す */
|
|
628
|
+
function registerTools(server, options) {
|
|
629
|
+
const context = {
|
|
630
|
+
data: options.data,
|
|
631
|
+
now: options.now ?? (() => /* @__PURE__ */ new Date())
|
|
632
|
+
};
|
|
633
|
+
const registered = [];
|
|
634
|
+
for (const tool of TOOLS) {
|
|
635
|
+
if (!options.scopes.includes(tool.scope)) continue;
|
|
636
|
+
if (options.enabled && !options.enabled(tool)) continue;
|
|
637
|
+
server.registerTool(tool.name, {
|
|
638
|
+
description: tool.description,
|
|
639
|
+
...tool.inputSchema ? { inputSchema: tool.inputSchema } : {},
|
|
640
|
+
annotations: tool.annotations
|
|
641
|
+
}, async (args) => {
|
|
642
|
+
try {
|
|
643
|
+
return toResult(await tool.run(context, args ?? {}));
|
|
644
|
+
} catch (caught) {
|
|
645
|
+
const message = failureMessage(caught);
|
|
646
|
+
if (message === null) throw caught;
|
|
647
|
+
return toResult({
|
|
648
|
+
kind: "error",
|
|
649
|
+
message
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
registered.push(tool.name);
|
|
654
|
+
}
|
|
655
|
+
return registered;
|
|
656
|
+
}
|
|
657
|
+
/** 道具を登録した MCP サーバーを作る */
|
|
658
|
+
function createFunmaryMcpServer(options) {
|
|
659
|
+
const server = new McpServer({
|
|
660
|
+
name: options.name ?? "funmary",
|
|
661
|
+
version: options.version ?? "1",
|
|
662
|
+
...options.icons ? { icons: [...options.icons] } : {}
|
|
663
|
+
});
|
|
664
|
+
registerTools(server, options);
|
|
665
|
+
return server;
|
|
666
|
+
}
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/stdio.ts
|
|
669
|
+
/** サーバーを起動して、標準入出力に結ぶ。トークンが使えなければ、理由の分かる文で、例外にする */
|
|
670
|
+
async function runStdioServer(options) {
|
|
671
|
+
const client = createFunmaryClient({
|
|
672
|
+
baseURL: options.baseURL,
|
|
673
|
+
token: options.token
|
|
674
|
+
});
|
|
675
|
+
let scopes;
|
|
676
|
+
try {
|
|
677
|
+
scopes = (await client.me()).scopes;
|
|
678
|
+
} catch (error) {
|
|
679
|
+
if (error instanceof FunmaryApiError && error.status === 401) throw new Error("アクセストークンが使えません。設定画面で発行し直してください", { cause: error });
|
|
680
|
+
throw error;
|
|
681
|
+
}
|
|
682
|
+
await createFunmaryMcpServer({
|
|
683
|
+
data: createClientData(client),
|
|
684
|
+
scopes,
|
|
685
|
+
...options.version ? { version: options.version } : {}
|
|
686
|
+
}).connect(new StdioServerTransport());
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
export { failureMessage as a, ambiguousMessage as c, TOOLS as i, createFunmaryMcpServer as n, createClientData as o, registerTools as r, FunmaryToolFailure as s, runStdioServer as t };
|
package/package.json
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@funmary/mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Funmary の MCP サーバー。手元で動かす (stdio) 入口と、サーバーと共有する道具の定義",
|
|
5
|
+
"license": "(BSD-3-Clause OR Apache-2.0)",
|
|
6
|
+
"author": "funmary (https://github.com/funmary-app)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/funmary-app/funmary.git",
|
|
10
|
+
"directory": "packages/public/mcp"
|
|
8
11
|
},
|
|
12
|
+
"type": "module",
|
|
9
13
|
"files": [
|
|
10
|
-
"
|
|
14
|
+
"dist"
|
|
11
15
|
],
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
"bin": {
|
|
17
|
+
"funmary-mcp": "./dist/bin.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"provenance": true
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@funmary/client": "1.0.0",
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.32.0",
|
|
35
|
+
"zod": "^4.6.5"
|
|
36
|
+
},
|
|
15
37
|
"devDependencies": {
|
|
16
|
-
"
|
|
17
|
-
|
|
38
|
+
"tsdown": "^0.23.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsdown"
|
|
18
42
|
}
|
|
19
43
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = console.log("@funmary/mcp is reserved for funmary");
|