tryastro-mcp 0.2.3 → 0.2.4

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.
Files changed (3) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/server.js +86 -29
package/README.md CHANGED
@@ -45,7 +45,7 @@ Use the published npm package:
45
45
  "mcpServers": {
46
46
  "tryastro-mcp": {
47
47
  "command": "npx",
48
- "args": ["-y", "tryastro-mcp@0.2.3"]
48
+ "args": ["-y", "tryastro-mcp@0.2.4"]
49
49
  }
50
50
  }
51
51
  }
@@ -56,7 +56,7 @@ Use the published npm package:
56
56
  1. Update `version` in `/package.json`.
57
57
  2. Login: `npm login`.
58
58
  3. Publish: `npm publish --access public`.
59
- 4. Verify install: `npx -y tryastro-mcp@0.2.3`.
59
+ 4. Verify install: `npx -y tryastro-mcp@0.2.4`.
60
60
 
61
61
  ## Data and source model
62
62
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tryastro-mcp",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "MCP server for TryAstro scenarios and standard support requests",
5
5
  "type": "module",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -7,7 +7,7 @@ import { fileURLToPath } from "node:url";
7
7
  function loadServerInfo() {
8
8
  const fallback = {
9
9
  name: "tryastro-mcp",
10
- version: "0.2.3",
10
+ version: "0.2.4",
11
11
  };
12
12
 
13
13
  try {
@@ -775,8 +775,16 @@ function makeError(id, code, message) {
775
775
  };
776
776
  }
777
777
 
778
+ let transportMode = null;
779
+
778
780
  function sendMessage(payload) {
779
781
  const encoded = JSON.stringify(payload);
782
+
783
+ if (transportMode === "line") {
784
+ process.stdout.write(`${encoded}\n`);
785
+ return;
786
+ }
787
+
780
788
  const bytes = Buffer.byteLength(encoded, "utf8");
781
789
  const header = `Content-Length: ${bytes}\r\n\r\n`;
782
790
  process.stdout.write(header + encoded);
@@ -830,6 +838,10 @@ function parseIncoming() {
830
838
  while (incoming.length > 0) {
831
839
  const boundary = findHeaderBoundary(incoming);
832
840
  if (!boundary) {
841
+ const lineStatus = tryParseLineDelimitedMessage();
842
+ if (lineStatus === "progress") {
843
+ continue;
844
+ }
833
845
  return;
834
846
  }
835
847
 
@@ -858,41 +870,86 @@ function parseIncoming() {
858
870
  continue;
859
871
  }
860
872
 
861
- if (Array.isArray(message)) {
862
- if (message.length === 0) {
863
- sendMessage(makeError(null, -32600, "Invalid Request: empty batch."));
864
- continue;
865
- }
873
+ if (!transportMode) {
874
+ transportMode = "content-length";
875
+ }
876
+ processDecodedMessage(message);
877
+ }
878
+ }
866
879
 
867
- const responses = [];
868
- for (const request of message) {
869
- if (!isObjectMessage(request)) {
870
- responses.push(
871
- makeError(null, -32600, "Invalid Request: request must be an object."),
872
- );
873
- continue;
874
- }
875
-
876
- const response = handleRequest(request);
877
- if (response) {
878
- responses.push(response);
879
- }
880
+ function processDecodedMessage(message) {
881
+ if (Array.isArray(message)) {
882
+ if (message.length === 0) {
883
+ sendMessage(makeError(null, -32600, "Invalid Request: empty batch."));
884
+ return;
885
+ }
886
+
887
+ const responses = [];
888
+ for (const request of message) {
889
+ if (!isObjectMessage(request)) {
890
+ responses.push(
891
+ makeError(null, -32600, "Invalid Request: request must be an object."),
892
+ );
893
+ continue;
880
894
  }
881
895
 
882
- if (responses.length > 0) {
883
- sendMessage(responses);
896
+ const response = handleRequest(request);
897
+ if (response) {
898
+ responses.push(response);
884
899
  }
885
- continue;
886
900
  }
887
901
 
888
- if (!isObjectMessage(message)) {
889
- sendMessage(makeError(null, -32600, "Invalid Request: request must be an object."));
890
- continue;
902
+ if (responses.length > 0) {
903
+ sendMessage(responses);
891
904
  }
905
+ return;
906
+ }
892
907
 
893
- const response = handleRequest(message);
894
- if (response) {
895
- sendMessage(response);
896
- }
908
+ if (!isObjectMessage(message)) {
909
+ sendMessage(makeError(null, -32600, "Invalid Request: request must be an object."));
910
+ return;
911
+ }
912
+
913
+ const response = handleRequest(message);
914
+ if (response) {
915
+ sendMessage(response);
916
+ }
917
+ }
918
+
919
+ function tryParseLineDelimitedMessage() {
920
+ const newlineIndex = incoming.indexOf("\n");
921
+ if (newlineIndex === -1) {
922
+ return "wait";
923
+ }
924
+
925
+ const rawLine = incoming.slice(0, newlineIndex).toString("utf8").replace(/\r$/, "");
926
+ incoming = incoming.slice(newlineIndex + 1);
927
+
928
+ const trimmed = rawLine.trim();
929
+ if (!trimmed) {
930
+ return "progress";
931
+ }
932
+
933
+ if (/^[A-Za-z-]+:\s*/.test(trimmed)) {
934
+ // Most likely an incomplete header block for Content-Length framing.
935
+ incoming = Buffer.concat([Buffer.from(rawLine + "\n", "utf8"), incoming]);
936
+ return "wait";
937
+ }
938
+
939
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
940
+ return "progress";
941
+ }
942
+
943
+ let message;
944
+ try {
945
+ message = JSON.parse(trimmed);
946
+ } catch {
947
+ return "progress";
948
+ }
949
+
950
+ if (!transportMode) {
951
+ transportMode = "line";
897
952
  }
953
+ processDecodedMessage(message);
954
+ return "progress";
898
955
  }