geo-figure-mcp 0.2.6 → 0.2.7

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2026 김한솔 (한백고등학교)
3
+ Copyright (c) 2026 barkhan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/README.md CHANGED
@@ -1,12 +1,12 @@
1
- # geo-figure-mcp — 지리 시험용 지도·그래프 만들기 (0.2.6)
1
+ # geo-figure-mcp — 지리 시험용 지도·그래프 만들기 (0.2.7)
2
2
 
3
- 만든 사람: 김한솔 (한백고등학교 지리 교사)
3
+ 만든 사람: barkhan (지리 교사)
4
4
 
5
5
  AI에게 "서울 자치구 주간 인구 지수 지도랑 산점도, 구 이름은 A~E로 숨겨서"처럼 말하면, **실제 통계**를 찾아 **흑백 시험지용** 지도·그래프를 만들어 줍니다.
6
6
  결과는 **PPTX·HWPX** 파일이고, 지역 한 칸·막대 하나·글자 하나까지 **도형**으로 들어갑니다(그림 파일이 아닙니다). 그룹 해제(개체 풀기)를 **한 번만** 하면 하나씩 고칠 수 있습니다.
7
7
 
8
8
  ## 무엇이 되나
9
- - **지도**: 한국 시·도 / 시·군·구(2026년 판, 16개 시·도), 세계·대륙(위·경도선), 단계 구분도(빗금·회색), A~E 기호, 지점, 흐름 화살표, 축척 자동, 경계 단순화 3단계
9
+ - **지도**: 한국 시·도 / 시·군·구(2026년 판, 16개 시·도), 세계·대륙(위·경도선과 숫자 눈금, graticule: 0으로 숨김), 단계 구분도(빗금·회색), A~E 기호, 지점, 흐름 화살표, 축척 자동, 경계 단순화 3단계
10
10
  - **지형**: 등고선 지형도·지형 단면(실제 표고), 교과서식 모식도 7종(암석 해안, 모래 해안·석호, 하안 단구, 카르스트, 화산, 빙하, 식생의 수직 분포)
11
11
  - **그래프**: 막대·누적 막대, 산점도·버블, 기후 그래프, 편차, 인구 피라미드, 삼각 그래프
12
12
  - **통계(실제 자료만, 숫자를 지어내지 않음)**
@@ -110,7 +110,7 @@ AI에게 "서울 자치구 주간 인구 지수 지도랑 산점도, 구 이름
110
110
  - 만든 파일은 **한 번 받으면 바로 지우고**, 안 받아도 60분 뒤 지웁니다(`KEEP_MINUTES`).
111
111
  - 서버에는 KOSIS 키가 없고, 원격에서는 KOSIS 직접 조회를 끕니다(키를 대화창에 붙여 넣지 않도록). 내장 통계만 씁니다.
112
112
  - 학교 양식 글꼴은 저장하지 않으니 `make_figures` 의 `style` 로 매번 넘깁니다.
113
- - 사용량 제한: IP마다 1분 60번·그림 1시간 30번, 서버 전체 그림 하루 300번(`DAILY_MAX`). 이름·학교 같은 개인정보는 받지 않고, IP는 사용량 계산에만 메모리에 잠깐 둡니다.
113
+ - 사용량 제한: IP마다 전체 MCP 요청 1분 60회, 파일 생성 1시간 90회, 서버 전체 파일 생성 하루 600회(`DAILY_MAX`). 이름·학교 같은 개인정보는 받지 않고, IP는 사용량 계산에만 메모리에 잠깐 둡니다.
114
114
  - 카드가 등록된 곳(Cloud Run 등)에 올리면 예산 알림과 최대 인스턴스 수를 꼭 정하세요.
115
115
  - 내 컴퓨터에서 시험: `ACCESS_TOKEN=아무거나 npm run start:remote` → `node examples/remote-test.js http://localhost:8787/mcp 아무거나`
116
116
 
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "geo-figure-mcp",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "지리 시험용 지도·그래프를 도형 하나하나 고칠 수 있는 PPTX·HWPX로 만드는 MCP 서버",
5
- "author": "김한솔 (한백고등학교)",
5
+ "author": "barkhan",
6
6
  "mcpName": "io.github.skyblue3925-svg/geo-figure-mcp",
7
7
  "type": "module",
8
8
  "bin": {
package/server.json CHANGED
@@ -4,12 +4,12 @@
4
4
  "title": "Geo Figure (지리 시험 지도·그래프)",
5
5
  "description": "지리 시험용 지도·그래프를 실제 통계로, 도형 하나하나 고칠 수 있는 PPTX·HWPX로 만든다.",
6
6
  "repository": { "url": "https://github.com/skyblue3925-svg/geo-figure-mcp", "source": "github" },
7
- "version": "0.2.6",
7
+ "version": "0.2.7",
8
8
  "packages": [
9
9
  {
10
10
  "registryType": "npm",
11
11
  "identifier": "geo-figure-mcp",
12
- "version": "0.2.6",
12
+ "version": "0.2.7",
13
13
  "transport": { "type": "stdio" },
14
14
  "environmentVariables": [
15
15
  { "name": "GEO_FIGURE_OUT", "description": "만든 파일을 저장할 폴더 (기본: 문서/지리시험자료)", "isRequired": false, "isSecret": false }
package/src/http.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // - 만든 파일: <PUBLIC_URL>/files/<무작위>/<이름> — 한 번 받으면 바로 지우고, 안 받아도 KEEP_MINUTES(기본 60분) 뒤 지운다
6
6
  // - ACCESS_TOKEN 필수: /mcp?token=… 또는 Authorization: Bearer … (비밀번호 없이 열려면 ALLOW_OPEN=1)
7
7
  // - 정답표는 파일에 넣지 않고 대화창에만 돌려준다. KOSIS 직접 조회는 원격에서 끈다(내장 자료만).
8
- // - 사용량: IP마다 1분 60번·그림 1시간 30번, 서버 전체 그림 하루 DAILY_MAX(기본 300)번
8
+ // - 사용량: IP마다 1분 60번·그림 1시간 90번, 서버 전체 그림 하루 DAILY_MAX(기본 600)번
9
9
  import http from 'node:http';
10
10
  import fs from 'node:fs';
11
11
  import os from 'node:os';
@@ -20,7 +20,8 @@ const FILES = process.env.FILES_DIR || path.join(os.tmpdir(), 'geo-figure-files'
20
20
  const TOKEN = process.env.ACCESS_TOKEN || '';
21
21
  const KEEP_MIN = +(process.env.KEEP_MINUTES || 60);
22
22
  const KEEP_MS = KEEP_MIN * 60 * 1000;
23
- const DAILY_MAX = +(process.env.DAILY_MAX || 300);
23
+ const MAKE_PER_HOUR = 90;
24
+ const DAILY_MAX = +(process.env.DAILY_MAX || 600);
24
25
  if (!TOKEN && process.env.ALLOW_OPEN !== '1') { console.error('ACCESS_TOKEN 을 정하세요(비밀번호 없이 열려면 ALLOW_OPEN=1).'); process.exit(1); }
25
26
  const tokenOk = (got) => { const a = Buffer.from(String(got || '')), b = Buffer.from(TOKEN); return a.length === b.length && crypto.timingSafeEqual(a, b); };
26
27
  let day = '', dayCount = 0;
@@ -41,7 +42,7 @@ setInterval(() => {
41
42
  }
42
43
  }, 5 * 60 * 1000).unref();
43
44
 
44
- // 사용량 제한: IP 마다 1분에 60번, 그림 만들기는 1시간에 30번
45
+ // 사용량 제한: IP 마다 1분에 60번, 그림 만들기는 1시간에 90번
45
46
  const hits = new Map();
46
47
  function limited(ip, kind, max, windowMs) {
47
48
  const k = `${ip}|${kind}`, now = Date.now();
@@ -84,7 +85,7 @@ const server = http.createServer(async (req, res) => {
84
85
  let body;
85
86
  try { body = JSON.parse(raw); } catch { return send(res, 400, { error: 'JSON 이 아닙니다.' }); }
86
87
  const isMake = [].concat(body).some((m) => m?.method === 'tools/call' && m?.params?.name === 'make_figures');
87
- if (isMake && limited(ip, 'make', 30, 3600 * 1000)) return send(res, 429, { error: '그림 만들기는 1시간에 30번까지입니다.' });
88
+ if (isMake && limited(ip, 'make', MAKE_PER_HOUR, 3600 * 1000)) return send(res, 429, { error: '같은 접속 IP에서는 최근 1시간에 ' + MAKE_PER_HOUR + '번까지 파일을 만들 수 있습니다.' });
88
89
  if (isMake && dailyOver()) return send(res, 429, { error: '오늘 서버 전체 사용량을 다 썼습니다. 내일 다시 쓰거나 내 컴퓨터에 설치해 쓰세요.' });
89
90
  try {
90
91
  const mcp = createServer({ remote: true, publish });
package/src/hwpx.js CHANGED
@@ -174,11 +174,7 @@ export function buildHwpx(figs, opts = {}) {
174
174
 
175
175
  const P = (inner, pp) => `<hp:p id="0" paraPrIDRef="${pp}" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">${inner}</hp:p>`;
176
176
  const cTitle = charPr(10, true), cBody = charPr(10, false);
177
- const body = [];
178
- // 쪽에 다 안 들어가는 그림은 제목부터 다음 쪽으로 넘긴다(넘치면 한글이 그림을 앞 그림 위에 겹쳐 놓는다)
179
- const USABLE = PAGE_H - 2 * MT - u(5) - u(7) - u(6);
180
- let used = 0;
181
- figs.forEach((f, k) => {
177
+ const drawings = figs.map((f, k) => {
182
178
  // 개체가 묶음 밖으로 나가면 한글이 묶음을 줄여 버린다 → 실제 범위를 재고, 음수면 옮겨서 다시 만든다
183
179
  // 한글은 '하나짜리 묶음'을 풀지 못한다 → 그림 안이 묶음 하나뿐이면 한 겹 벗긴다
184
180
  let items = f.items;
@@ -192,9 +188,18 @@ export function buildHwpx(figs, opts = {}) {
192
188
  }
193
189
  const W = Math.max(u(f.w), ext[2]), H = Math.max(u(f.h), ext[3]);
194
190
  const cont = `<hp:container id="${next()}" zOrder="${k}" numberingType="PICTURE" textWrap="IN_FRONT_OF_TEXT" textFlow="BOTH_SIDES" lock="0" dropcapstyle="None" href="" groupLevel="0" instid="${next()}"><hp:offset x="0" y="0"/><hp:orgSz width="${W}" height="${H}"/><hp:curSz width="0" height="0"/><hp:flip horizontal="0" vertical="0"/><hp:rotationInfo angle="0" centerX="${Math.round(W / 2)}" centerY="${Math.round(H / 2)}" rotateimage="1"/><hp:renderingInfo><hc:transMatrix ${I}/><hc:scaMatrix ${I}/><hc:rotMatrix ${I}/></hp:renderingInfo>${objs.join('')}<hp:sz width="${W}" widthRelTo="ABSOLUTE" height="${H}" heightRelTo="ABSOLUTE" protect="0"/><hp:pos treatAsChar="0" affectLSpacing="0" flowWithText="1" allowOverlap="1" holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="COLUMN" vertAlign="TOP" horzAlign="LEFT" vertOffset="0" horzOffset="0"/><hp:outMargin left="0" right="0" top="0" bottom="${u(4)}"/><hp:shapeComment>${esc(f.title || '그림')}</hp:shapeComment></hp:container>`;
195
- const first = k === 0 ? secPr() : '';
191
+ return { f, cont, W, H };
192
+ });
193
+
194
+ const landscape = drawings.some(({ W }) => W > PAGE_W - 2 * ML);
195
+ // 쪽에 다 안 들어가는 그림은 제목부터 다음 쪽으로 넘긴다(넘치면 한글이 그림을 앞 그림 위에 겹쳐 놓는다)
196
+ const usable = (landscape ? PAGE_W : PAGE_H) - 2 * MT - u(5) - u(7) - u(6);
197
+ const body = [];
198
+ let used = 0;
199
+ drawings.forEach(({ f, cont, H }, k) => {
200
+ const first = k === 0 ? secPr(landscape) : '';
196
201
  const need = u(8) + H + u(8);
197
- const brk = k > 0 && used + need > USABLE;
202
+ const brk = k > 0 && used + need > usable;
198
203
  used = brk ? need : used + need;
199
204
  body.push(P(`<hp:run charPrIDRef="${cTitle}">${first}<hp:t>${esc(f.title || '')}</hp:t></hp:run>`, paraPr('LEFT', 130, u(2))).replace('pageBreak="0"', `pageBreak="${brk ? 1 : 0}"`));
200
205
  // 그림은 '글 앞으로' 띄우고, 그림 높이만큼 고정 높이 문단으로 자리를 비운다 → 묶음을 풀어도 조각이 밀리지 않는다
@@ -222,12 +227,12 @@ export function buildHwpx(figs, opts = {}) {
222
227
  return zipSync(files, { level: 6 });
223
228
  }
224
229
 
225
- function secPr() {
230
+ function secPr(landscape) {
226
231
  return '<hp:secPr id="" textDirection="HORIZONTAL" spaceColumns="1134" tabStop="8000" tabStopVal="4000" tabStopUnit="HWPUNIT" outlineShapeIDRef="1" memoShapeIDRef="0" textVerticalWidthHead="0" masterPageCnt="0">'
227
232
  + '<hp:grid lineGrid="0" charGrid="0" wonggojiFormat="0"/><hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/>'
228
233
  + '<hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/>'
229
234
  + '<hp:lineNumberShape restartType="0" countBy="0" distance="0" startNumber="0"/>'
230
- + `<hp:pagePr landscape="WIDELY" width="${PAGE_W}" height="${PAGE_H}" gutterType="LEFT_ONLY"><hp:margin header="${u(5)}" footer="${u(7)}" gutter="0" left="${ML}" right="${ML}" top="${MT}" bottom="${MT}"/></hp:pagePr>`
235
+ + `<hp:pagePr landscape="${landscape ? 'NARROWLY' : 'WIDELY'}" width="${PAGE_W}" height="${PAGE_H}" gutterType="LEFT_ONLY"><hp:margin header="${u(5)}" footer="${u(7)}" gutter="0" left="${ML}" right="${ML}" top="${MT}" bottom="${MT}"/></hp:pagePr>`
231
236
  + '<hp:footNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="EACH_COLUMN" beneathText="0"/></hp:footNotePr>'
232
237
  + '<hp:endNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="END_OF_DOCUMENT" beneathText="0"/></hp:endNotePr>'
233
238
  + ['BOTH', 'EVEN', 'ODD'].map((t) => `<hp:pageBorderFill type="${t}" borderFillIDRef="1" textBorder="PAPER" headerInside="0" footerInside="0" fillArea="PAPER"><hp:offset left="1417" right="1417" top="1417" bottom="1417"/></hp:pageBorderFill>`).join('')
package/src/maps.js CHANGED
@@ -116,11 +116,7 @@ export function makeMap(spec, st = DEFAULT_STYLE) {
116
116
  const path = geoPath(proj);
117
117
 
118
118
  const items = [];
119
- if (!isKorea && spec.graticule !== 0) {
120
- const step = spec.graticule || 10;
121
- const gl = lines(path, geoGraticule().step([step, step])());
122
- items.push(S.group('위·경도선', gl.map((l) => S.line(l, { stroke: 0.12, dash: 'sysDash', gray: '#7F7F7F', name: '위·경도선' }))));
123
- }
119
+
124
120
  // 단계 구분에 지도에 없는 이름이 있으면 조용히 빠지지 않게 알린다
125
121
  if (spec.classes) {
126
122
  const bad = Object.keys(spec.classes).filter((n) => !feats.some((f) => f.full === n || f.name === n || f.id === n));
@@ -136,6 +132,10 @@ export function makeMap(spec, st = DEFAULT_STYLE) {
136
132
  areas.push(S.poly(rs, { fill, stroke: inFocus.has(f) ? 0.2 : 0.12, name: f.full }));
137
133
  }
138
134
  items.push(S.group(isKorea ? '행정 구역' : '국가', areas));
135
+ if (!isKorea && spec.graticule !== 0) {
136
+ const step = spec.graticule || (!spec.bbox || spec.bbox[2] - spec.bbox[0] > 150 ? 30 : 10);
137
+ items.push(worldGrid(path, step, st));
138
+ }
139
139
  const isSigungu = spec.level === 'sigungu';
140
140
  if (isKorea && (isSigungu || spec.within?.length)) {
141
141
  const sidos = isSigungu ? koreaFeatures('sido', detail, spec.edition) : feats;
@@ -201,6 +201,40 @@ export function makeMap(spec, st = DEFAULT_STYLE) {
201
201
  return items;
202
202
  }
203
203
 
204
+ function worldGrid(path, step, st) {
205
+ const grid = [], meridians = [], parallels = [];
206
+ for (const line of geoGraticule().step([step, step]).lines()) {
207
+ const [first, second] = line.coordinates;
208
+ const meridian = first[0] === second[0];
209
+ const angle = +first[meridian ? 0 : 1].toFixed(8);
210
+ const segments = lines(path, line);
211
+ if (!segments.length) continue;
212
+ const points = segments.flat();
213
+ const x = Math.min(...points.map((p) => p[0]));
214
+ const y = Math.min(...points.map((p) => p[1]));
215
+ const suffix = angle === 0 || Math.abs(angle) === 180 ? '' : meridian ? (angle < 0 ? 'W' : 'E') : (angle < 0 ? 'S' : 'N');
216
+ const label = Math.abs(angle) + '°' + suffix;
217
+ const size = st.small;
218
+ if (meridian) {
219
+ meridians.push({ angle, at: x, span: textWidth(label, size), item: S.text(x, y - 1.2, label, { size, v: 'b', name: '경도 눈금' }) });
220
+ } else {
221
+ parallels.push({ angle, at: y, span: size * 0.3528 * 1.25, item: S.text(x - 1.2, y, label, { size, anchor: 'r', name: '위도 눈금' }) });
222
+ }
223
+ for (const pts of segments) grid.push(S.line(pts, { stroke: 0.25, dash: 'sysDash', gray: '#707070', name: '위·경도선' }));
224
+ }
225
+ // 눈금 글자가 겹치면 적도와 본초 자오선에 가까운 눈금을 우선한다.
226
+ for (const ticks of [meridians, parallels]) {
227
+ const placed = [];
228
+ ticks.sort((a, b) => Math.abs(a.angle) - Math.abs(b.angle));
229
+ for (const tick of ticks) {
230
+ if (placed.some((p) => Math.abs(p.at - tick.at) < (p.span + tick.span) / 2 + 1)) continue;
231
+ placed.push(tick);
232
+ grid.push(tick.item);
233
+ }
234
+ }
235
+ return S.group('위·경도선과 눈금', grid);
236
+ }
237
+
204
238
  function scaleBar(proj, W, H, st) {
205
239
  const y = H - 3, x0 = 3;
206
240
  const a = proj.invert([x0, y]), b = proj.invert([x0 + 10, y]);
package/src/svg.js CHANGED
@@ -47,6 +47,6 @@ export function buildSvg(fig, style = DEFAULT_STYLE) {
47
47
 
48
48
  // PNG(가로 px). 글꼴은 이 컴퓨터에 깔린 한글 글꼴을 쓴다.
49
49
  export function renderPng(fig, { width = 900, style } = {}) {
50
- const r = new Resvg(buildSvg(fig, style), { fitTo: { mode: 'width', value: width }, font: { loadSystemFonts: true, defaultFontFamily: 'Malgun Gothic' }, background: '#FFFFFF' });
50
+ const r = new Resvg(buildSvg(fig, style), { fitTo: { mode: 'width', value: width }, font: { loadSystemFonts: true, defaultFontFamily: process.platform === 'linux' ? 'Noto Sans CJK KR' : 'Malgun Gothic' }, background: '#FFFFFF' });
51
51
  return r.render().asPng();
52
52
  }
package/src/tools.js CHANGED
@@ -337,7 +337,8 @@ map:
337
337
  labelStyle: 'halo', // 기호 글자: halo(흰 테두리, 기본) | plain(바탕 없음) | box(네모 흰 바탕) | circle(작은 원 흰 바탕)
338
338
  points:[{ lon, lat, label:'A' }], // 점 + 기호 (도시·기후 지점)
339
339
  flows:[{ from:'경기', to:'서울', value:120 }], // 흐름 화살표(굵기 = 값)
340
- graticule:20, scaleBar:true|false, edition:'2026'|'2025' }
340
+ graticule:20, // 세계지도 위·경도선 간격(도). 생략하면 자동, 0이면 선과 눈금 모두 숨김
341
+ scaleBar:true|false, edition:'2026'|'2025' }
341
342
  - 시·군·구 이름은 '서울 종로구'처럼 '시·도 짧은이름 + 이름'. 필요할 때 list_regions에 query와 edition으로 확인.
342
343
  `,
343
344
  chart: `